<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/dute_favicon_32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/dute_favicon_16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="google-site-verification" content="mpI5dkydstZXl6UcDCppqktXK0bbvqdZ6LkZ3KNk4Iw">
  <meta name="baidu-site-verification" content="code-a1LksZX2Ds">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"whitestore.top","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Elasticsearch 踩坑 - 6.2.4 版本">
<meta property="og:type" content="article">
<meta property="og:title" content="ElasticSearch6.2.4 踩坑">
<meta property="og:url" content="https://whitestore.top/2020/07/26/note9/index.html">
<meta property="og:site_name" content="爱看书的阿东">
<meta property="og:description" content="Elasticsearch 踩坑 - 6.2.4 版本">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-07-26T13:32:58.000Z">
<meta property="article:modified_time" content="2023-07-16T06:28:09.221Z">
<meta property="article:author" content="阿东">
<meta property="article:tag" content="Elasticsearch">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://whitestore.top/2020/07/26/note9/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>ElasticSearch6.2.4 踩坑 | 爱看书的阿东</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="爱看书的阿东" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">爱看书的阿东</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">赐他一块白色石头，石头上写着新名</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://whitestore.top/2020/07/26/note9/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="阿东">
      <meta itemprop="description" content="随遇而安">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱看书的阿东">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ElasticSearch6.2.4 踩坑
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-26 21:32:58" itemprop="dateCreated datePublished" datetime="2020-07-26T21:32:58+08:00">2020-07-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-07-16 14:28:09" itemprop="dateModified" datetime="2023-07-16T14:28:09+08:00">2023-07-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/ElasticSearch/" itemprop="url" rel="index"><span itemprop="name">ElasticSearch</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/07/26/note9/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/07/26/note9/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>105k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1:35</span>
            </span>
            <div class="post-description">Elasticsearch 踩坑 - 6.2.4 版本</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="ElasticSearch-踩坑-6-2-4-版本"><a href="#ElasticSearch-踩坑-6-2-4-版本" class="headerlink" title="ElasticSearch 踩坑 - 6.2.4 版本"></a>ElasticSearch 踩坑 - 6.2.4 版本</h1><h1 id="目标"><a href="#目标" class="headerlink" title="目标"></a>目标</h1><h2 id="自定义评分器"><a href="#自定义评分器" class="headerlink" title="自定义评分器"></a>自定义评分器</h2><p><strong>可以根据自己的规则去调整搜索结果的评分，修改权重</strong></p>
<ol>
<li>需要根据用户标签以及网站标签，收集用户最关注的标签内容，进行标签标记</li>
<li>收集数据生成可视化报告</li>
<li>关键字查询，基于用户的网站标签内容建设</li>
<li>形成综合信息关联库。以核心用户标签和核心业务标签为参考，对重点资源进行归纳合并，形成重点主题资源关联关系对应表。</li>
<li>设计一个标签关联模块，可以由运维进行标签关联的配置,即给用户分配权重</li>
</ol>
<a id="more"></a>

<h2 id="智能推荐："><a href="#智能推荐：" class="headerlink" title="智能推荐："></a>智能推荐：</h2><p>搜索优化查询</p>
<h1 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h1><ul>
<li><a href="#elasticsearch-踩坑-624-版本">Elasticsearch 踩坑 - 6.2.4 版本</a></li>
<li>目标<ul>
<li><a href="#自定义评分器">自定义评分器</a></li>
<li><a href="#智能推荐">智能推荐：</a></li>
</ul>
</li>
<li><a href="#目录">目录</a></li>
<li>官方改变1<ul>
<li><a href="#restful请求需要加入header">RestFul请求需要加入Header</a></li>
</ul>
</li>
<li>官方改变2：<ul>
<li><a href="#分词器-n元语法ngram">分词器 N元语法ngram</a></li>
</ul>
</li>
<li>\1. 基本使用<ul>
<li><a href="#11-创建索引">1.1 创建索引</a></li>
<li><a href="#12-查看索引信息">1.2 查看索引信息:</a></li>
<li>1.3 创建类型<ul>
<li><a href="#132-指定id的方式">1.3.2 指定id的方式：</a></li>
<li><a href="#131-不指定id的方式">1.3.1 不指定id的方式</a></li>
</ul>
</li>
<li><a href="#14-创建一个文档">1.4 创建一个文档</a></li>
</ul>
</li>
<li>\2. 基础搜索<ul>
<li>2.1 使用query 进行搜索<ul>
<li><a href="#原始方式">原始方式</a></li>
<li>kibana方式<ul>
<li><a href="#211-如果只想查找一个字段可以使用term">2.1.1 如果只想查找一个字段，可以使用term</a></li>
</ul>
</li>
</ul>
</li>
<li>2.2 过滤器<ul>
<li><a href="#221-es6以下">2.2.1 ES6以下：</a></li>
<li><a href="#222-es6及以上">2.2.2 ES6及以上：</a></li>
</ul>
</li>
<li>2.3 应用聚集<ul>
<li><a href="#231-es6以下">2.3.1 ES6以下：</a></li>
<li><a href="#232-es6及以上">2.3.2 ES6及以上：</a></li>
</ul>
</li>
<li><a href="#24-通过id获取文档">2.4 通过Id获取文档</a></li>
</ul>
</li>
<li>\3. elasticsearch配置<ul>
<li><a href="#31-指定集群名称">3.1 指定集群名称：</a></li>
<li><a href="#32-指定详细的日志记录">3.2 指定详细的日志记录</a></li>
<li>3.3 调整虚拟机大小<ul>
<li><a href="#331-linux-使用如下命令">3.3.1 linux 使用如下命令：</a></li>
<li><a href="#332-使用elasticsearchyml修改启动堆内存大小">3.3.2 使用elasticsearch.yml修改启动堆内存大小</a></li>
<li><a href="#333-使用修改binelasticsearchinsh-修改">3.3.3 使用修改bin/elasticsearch.in.sh 修改</a></li>
</ul>
</li>
<li>3.4 集群中加入节点<ul>
<li><a href="#341-查看节点状态">3.4.1 查看节点状态</a></li>
</ul>
</li>
</ul>
</li>
<li>\4. 映射_mapping<ul>
<li>4.1 检索和自定义映射<ul>
<li><a href="#411-获取目前的映射">4.1.1 获取目前的映射</a></li>
<li><a href="#412-获取自动生成的映射">4.1.2 获取自动生成的映射</a></li>
<li>4.1.3 定义新的映射<ul>
<li><a href="#es6以下版本">es6以下版本</a></li>
<li><a href="#es6以上版本">es6以上版本</a></li>
</ul>
</li>
<li><a href="#414-改变现有字段类型的方法">4.1.4 改变现有字段类型的方法：</a></li>
</ul>
</li>
<li>4.2 用于定义文档字段的核心类型<ul>
<li><a href="#421-定义映射当中的index选项">4.2.1 定义映射当中的index选项</a></li>
<li><a href="#422-如何创建嵌套类型">4.2.2 如何创建嵌套类型：</a></li>
<li><a href="#423-定义多字段和数组类型">4.2.3 定义多字段和数组类型</a></li>
</ul>
</li>
<li>4.3 使用预定义字段<ul>
<li><a href="#431-控制如何存储和搜索文档">4.3.1 控制如何存储和搜索文档</a></li>
</ul>
</li>
<li>4.4 更新现有文档<ul>
<li><a href="#441-文档更新包含如下步骤">4.4.1 文档更新包含如下步骤：</a></li>
</ul>
</li>
<li>4.5 删除文档<ul>
<li><a href="#451-删除文档的方式">4.5.1 删除文档的方式</a></li>
<li><a href="#452-删除文档">4.5.2 删除文档</a></li>
<li><a href="#453-删除单个文档">4.5.3 删除单个文档</a></li>
<li><a href="#454-删除映射类型和删除查询匹配的文档">4.5.4 删除映射类型和删除查询匹配的文档</a></li>
<li><a href="#455-删除索引">4.5.5 删除索引</a></li>
<li><a href="#456-关闭和开发索引">4.5.6 关闭和开发索引</a></li>
</ul>
</li>
</ul>
</li>
<li>\5. 版本控制<ul>
<li>5.1 乐观锁<ul>
<li><a href="#511-内部版本控制">5.1.1 内部版本控制</a></li>
<li><a href="#512-外部版本控制">5.1.2 外部版本控制</a></li>
</ul>
</li>
<li><a href="#52-自动重试">5.2 自动重试</a></li>
</ul>
</li>
<li>\6. 搜索与高级搜索分析<ul>
<li><a href="#61-搜索请求的基本模块">6.1 搜索请求的基本模块</a></li>
<li>6.2 基于url的搜索请求<ul>
<li><a href="#621-基于from-和szize的参数来实现结果分页">6.2.1 基于from 和szize的参数来实现结果分页</a></li>
<li><a href="#622-改变结果的顺序">6.2.2 改变结果的顺序</a></li>
<li><a href="#623-搜索结果当中限制_source-字段">6.2.3 搜索结果当中限制_source 字段</a></li>
<li><a href="#624-匹配查询">6.2.4 匹配查询</a></li>
</ul>
</li>
<li>6.3 基于请求主体的搜索请求<ul>
<li><a href="#631-使用from-和-size参数结果分页">6.3.1 使用from 和 size，参数结果分页</a></li>
<li>6.3.2 过滤返回_source 内容<ul>
<li><a href="#在source字段当中返回通配符">在source字段当中返回通配符</a></li>
<li><a href="#通过include以及exclude-过滤返回_source的内容">通过include以及exclude 过滤返回_source的内容</a></li>
</ul>
</li>
<li><a href="#633-基于结果的排序">6.3.3 基于结果的排序</a></li>
</ul>
</li>
<li>6.4 实践中的基础模块<ul>
<li><a href="#641-理解回复的内容">6.4.1 理解回复的内容</a></li>
</ul>
</li>
<li>6.5 查询和过滤器DSL （重点）<ul>
<li>6.5.1 match 查询和term过滤器<ul>
<li><a href="#过滤器和查询器有什么不同">过滤器和查询器有什么不同：</a></li>
<li><a href="#es6以下-以及旧版本使用的方式">es6以下 以及旧版本使用的方式</a></li>
<li><a href="#font-colorred这里需要注意下面使用的是es6以及以上版本font">这里需要注意下面使用的是es6以及以上版本</a></li>
</ul>
</li>
</ul>
</li>
<li>6.6 常用的基础查询和过滤器<ul>
<li><a href="#661-match_all-的使用场景">6.6.1 match_all 的使用场景</a></li>
<li>6.6.2 query_string 查询<ul>
<li><a href="#使用query_string-进行复杂的查询">使用query_string 进行复杂的查询</a></li>
</ul>
</li>
<li>6.6.3 term 查询和 term过滤器<ul>
<li><a href="#使用term-过滤器的得分和term查询器的得分对比">使用term 过滤器的得分，和term查询器的得分对比</a></li>
</ul>
</li>
<li><a href="#664-terms-查询">6.6.4 terms 查询</a></li>
<li>6.5.5 match查询和 term过滤器<ul>
<li><a href="#布尔查询行为">布尔查询行为</a></li>
<li>词组（phrase ）查询的方式<ul>
<li><a href="#es5版本以及以下的语法">es5版本以及以下的语法：</a></li>
<li><a href="#es6以及以上要使用以下语法">es6以及以上要使用以下语法</a></li>
</ul>
</li>
</ul>
</li>
<li>6.5.6 phrase_prefix 查询<ul>
<li><a href="#es5x-版本以及以下的语法">es5.x 版本以及以下的语法：</a></li>
<li><a href="#es6x-需要改成如下写法">es6.x 需要改成如下写法</a></li>
<li><a href="#使用multi_match-匹配多个字段">使用multi_match 匹配多个字段</a></li>
</ul>
</li>
</ul>
</li>
<li>6.7 组合查询和复合查询<ul>
<li><a href="#671-bool查询">6.7.1 bool查询</a></li>
<li><a href="#672-bool-的过滤器">6.7.2 bool 的过滤器</a></li>
</ul>
</li>
<li>6.8 超越match 和 过滤器的查询<ul>
<li>6.8.1 range 查询和过滤器<ul>
<li><a href="#模拟数据">模拟数据</a></li>
<li><a href="#现在需要查找出-11-年到-16年的数据">现在需要查找出 11 年到 16年的数据</a></li>
</ul>
</li>
<li>6.8.2 prefix 查询和过滤器<ul>
<li><a href="#在过滤器当中使用">在过滤器当中使用</a></li>
</ul>
</li>
<li><a href="#683-wildcard-查询">6.8.3 wildcard 查询</a></li>
</ul>
</li>
<li>6.9 使用过滤器查询字段的存在性<ul>
<li><a href="#691-exists-过滤器">6.9.1 exists 过滤器</a></li>
<li>6.9.2 missing 过滤器（6.x以上版本已经删除）<ul>
<li><a href="#作为测试先插入一条增加一个字段的数据">作为测试,先插入一条增加一个字段的数据</a></li>
<li><a href="#接下来查找字段里没有的值这样写是错误的没有正确写法6x">接下来，查找字段里没有的值,这样写是错误的，没有正确写法（6.x）</a></li>
</ul>
</li>
<li>6.9.3 将任何查询转为过滤器<ul>
<li><a href="#缓存过滤器">缓存过滤器</a></li>
</ul>
</li>
<li><a href="#694-为任务选择最好的查询">6.9.4 为任务选择最好的查询</a></li>
</ul>
</li>
</ul>
</li>
<li>\7. 分析数据<ul>
<li>7.1 什么是分析数据<ul>
<li><a href="#711-字符过滤">7.1.1 字符过滤</a></li>
<li><a href="#712-切分为分词">7.1.2 切分为分词</a></li>
<li><a href="#713-分词过滤器">7.1.3 分词过滤器</a></li>
<li><a href="#714-分词索引">7.1.4 分词索引</a></li>
</ul>
</li>
<li>7.2 为文档使用分析器<ul>
<li>7.2.1 创建索引的过程中，添加定制分析器<ul>
<li><a href="#旧版本的使用方式">旧版本的使用方式</a></li>
<li><a href="#网上的案例">网上的案例：</a></li>
<li><a href="#将书上的案例改为6x支持的形式格式如下">将书上的案例改为6.x支持的形式，格式如下:</a></li>
</ul>
</li>
<li><a href="#722-使用elasticsearchyml-的配置文件进行配置">7.2.2 使用elasticsearch.yml 的配置文件进行配置</a></li>
<li>7.2.3 在映射中指定某个字段的分析器<ul>
<li><a href="#书本的方式已经不适用于6x版本了根据官方文档的内容要进行如下定义">书本的方式已经不适用于6.x版本了，根据官方文档的内容要进行如下定义</a></li>
</ul>
</li>
</ul>
</li>
<li>7.3 使用API来分析文本<ul>
<li><a href="#731-使用_analyzer-内置api来进行分析分析器解析步骤">7.3.1 使用_analyzer 内置API来进行分析分析器解析步骤</a></li>
<li><a href="#732-分析中指定自定义分析器">7.3.2 分析中指定自定义分析器</a></li>
<li>7.3.3 使用组合即时创建分析器<ul>
<li><a href="#使用curl方式">使用curl方式</a></li>
<li><a href="#使用kibana方式">使用kibana方式</a></li>
</ul>
</li>
<li><a href="#734-使用基于某个字段的映射分析">7.3.4 使用基于某个字段的映射分析</a></li>
<li><a href="#735-使用词条向量api来学习索引词条">7.3.5 使用词条向量API来学习索引词条</a></li>
</ul>
</li>
<li>7.4 分析器/分词器和分词过滤器<ul>
<li><a href="#740-分析器的概览">7.4.0 分析器的概览</a></li>
<li>7.4.1 内置分析器<ul>
<li><a href="#标准分析器">标准分析器</a></li>
<li><a href="#简单分析器"><strong>简单分析器</strong></a></li>
<li><a href="#空白分析器"><strong>空白分析器</strong></a></li>
<li><a href="#停止分析器"><strong>停止分析器</strong></a></li>
<li><a href="#关键字分析器"><strong>关键字分析器</strong></a></li>
<li><a href="#模式分析器"><strong>模式分析器</strong></a></li>
<li><a href="#语言分析器"><strong>语言分析器</strong></a></li>
<li><a href="#指纹分析器"><strong>指纹分析器</strong></a></li>
<li><a href="#雪球分析器">雪球分析器</a></li>
</ul>
</li>
<li>7.4.2 分词器<ul>
<li><a href="#标准分词器"><strong>标准分词器</strong></a></li>
<li><a href="#字母分词器"><strong>字母分词器</strong></a></li>
<li><a href="#小写分词器"><strong>小写分词器</strong></a></li>
<li><a href="#空格分词器"><strong>空格分词器</strong></a></li>
<li><a href="#uax-url电子邮件令牌生成器">UAX URL电子邮件令牌生成器</a></li>
<li><a href="#经典分词器">经典分词器</a></li>
<li><a href="#泰语分词器">泰语分词器</a></li>
</ul>
</li>
<li>7.4.3 分词过滤器<ul>
<li><a href="#标准分词过滤器">标准分词过滤器</a></li>
<li><a href="#ascii-folding-token-filterascii折叠过滤器">ASCII Folding Token Filter（ASCII折叠过滤器）</a></li>
<li><a href="#flatten-graph-token-filter图形分词过滤器">Flatten Graph Token Filter（图形分词过滤器）</a></li>
<li><a href="#length-token-filter长度分词过滤器">Length Token Filter（长度分词过滤器）</a></li>
<li><a href="#lowercase-token-filter小写分词过滤器">Lowercase token filter（小写分词过滤器）</a></li>
<li><a href="#uppercase-token-filter大写分词过滤器">Uppercase Token Filter（大写分词过滤器）</a></li>
<li><a href="#ngram-token-filtern元语法过滤器">NGram Token Filter（N元语法过滤器）</a></li>
<li><a href="#edge-ngram-token-filter侧边n元语法过滤器">Edge NGram Token Filter（侧边N元语法过滤器）</a></li>
</ul>
</li>
<li>7.4.4 N元语法的使用场景以及使用案例<ul>
<li><a href="#使用案例">使用案例:</a></li>
<li><span class="exturl" data-url="aHR0cHM6Ly93d3cuZWxhc3RpYy5jby9ndWlkZS9lbi9lbGFzdGljc2VhcmNoL3JlZmVyZW5jZS82LjQvYW5hbHlzaXMtc2hpbmdsZS10b2tlbmZpbHRlci5odG1s" title="https://www.elastic.co/guide/en/elasticsearch/reference/6.4/analysis-shingle-tokenfilter.html">Shingle Token Filter<i class="fa fa-external-link"></i></span>（滑动窗口分词过滤器）</li>
</ul>
</li>
</ul>
</li>
<li>7.5 提取词干<ul>
<li>7.5.1 算分提取词干<ul>
<li><a href="#选取kstem-作为案例测试">选取kstem 作为案例测试</a></li>
</ul>
</li>
<li><a href="#752-使用字典提取词干">7.5.2 使用字典提取词干</a></li>
</ul>
</li>
</ul>
</li>
<li>\8. 使用相关性进行搜索<ul>
<li>8.1 es 的打分机制<ul>
<li><a href="#811-文档是如何运作的">8.1.1 文档是如何运作的：</a></li>
<li><a href="#812-词频">8.1.2 词频</a></li>
<li><a href="#813-逆文档词频">8.1.3 逆文档词频</a></li>
<li><a href="#814-lucene-评分公式">8.1.4 Lucene 评分公式</a></li>
</ul>
</li>
<li>8.2 其他打分方式<ul>
<li><a href="#如何指定索引的打分方式">如何指定索引的打分方式？</a></li>
</ul>
</li>
<li><a href="#83-索引期间boosting">8.3 索引期间Boosting</a></li>
<li>8.4 查询期间的Boosting<ul>
<li><a href="#841-跨越多个字段的查询">8.4.1 跨越多个字段的查询</a></li>
<li><a href="#842-使用multi_match-查询指定整个boost">8.4.2 使用multi_match 查询，指定整个Boost</a></li>
<li><a href="#843-使用特殊符号对于name-进行boost">8.4.3 使用特殊符号^对于name 进行boost</a></li>
<li><a href="#844-query_string-中对于针对单个的词条进行boost">8.4.4 query_string 中对于针对单个的词条进行boost</a></li>
</ul>
</li>
<li>8.5 使用”解释(explain)”来理解文档评分<ul>
<li><a href="#851-解释一篇文档不匹配的原因">8.5.1 解释一篇文档不匹配的原因</a></li>
</ul>
</li>
<li>8.6 使用查询再打分来减小评分操作影响<ul>
<li><a href="#861-官方文档介绍-62版本">8.6.1 官方文档介绍 6.2版本</a></li>
<li><a href="#862-使用rescore-特性对于匹配文档子集再评分">8.6.2 使用rescore 特性，对于匹配文档子集再评分</a></li>
</ul>
</li>
<li>8.7 function_score 来定制得分<ul>
<li><a href="#871-function_score-的基本结构">8.7.1 function_score 的基本结构</a></li>
<li>8.7.2 weight 函数<ul>
<li><a href="#可以指定多个weight函数">可以指定多个weight函数</a></li>
</ul>
</li>
<li><a href="#873-合并得分">8.7.3 合并得分</a></li>
<li><a href="#874-field_value_factor-函数">8.7.4 field_value_factor 函数</a></li>
<li><a href="#875-在function_score-查询中使用field_value_factor">8.7.5 在function_score 查询中使用field_value_factor</a></li>
</ul>
</li>
<li>8.8 painless脚本(5.0后go语言脚本支持已删除)<ul>
<li><a href="#875-random_score-函数">8.7.5 random_score 函数</a></li>
<li>8.7.6 衰减函数<ul>
<li><a href="#官方文档">官方文档</a></li>
<li><a href="#配置选项">配置选项</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#89-使用脚本排序">8.9 使用脚本排序</a></li>
</ul>
</li>
<li>\9. Elasticsearch REST API 的学习使用<ul>
<li><a href="#90-api官网">9.0 API官网</a></li>
<li>9.1 REST 低级 Api<ul>
<li><a href="#911-起步">9.1.1 起步</a></li>
<li><a href="#912-初始化">9.1.2 初始化</a></li>
<li><a href="#913-执行请求">9.1.3 执行请求</a></li>
<li><a href="#914-接受响应体的处理">9.1.4 接受响应体的处理</a></li>
</ul>
</li>
<li>9.2 REST 高级 API<ul>
<li><a href="#921-机器翻译介绍">9.2.1 机器翻译介绍</a></li>
<li><a href="#922-兼容性">9.2.2 </a><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2VsYXN0aWMvZWxhc3RpY3NlYXJjaC9lZGl0LzYuMi9kb2NzL2phdmEtcmVzdC9oaWdoLWxldmVsL2dldHRpbmctc3RhcnRlZC5hc2NpaWRvYw==" title="https://github.com/elastic/elasticsearch/edit/6.2/docs/java-rest/high-level/getting-started.asciidoc">兼容性<i class="fa fa-external-link"></i></span></li>
<li><a href="#923-起步">9.2.3 起步</a></li>
<li><a href="#924-创建一个rest-连接">9.2.4 创建一个rest 连接</a></li>
<li>9.2.5 【6.2.4】版本 支持的相关API （重点）<ul>
<li><a href="#创建索引">创建索引</a></li>
<li><a href="#删除索引">删除索引</a></li>
<li><a href="#开放索引">开放索引</a></li>
<li><a href="#关闭索引">关闭索引</a></li>
</ul>
</li>
<li>9.2.6 索引本身的API<ul>
<li><a href="#直接根据索引创建一个文档需要如下参数">直接根据索引创建一个文档需要如下参数</a></li>
<li><a href="#提供文档来源的多种方式">提供文档来源的多种方式</a></li>
<li><a href="#可选参数">可选参数</a></li>
<li><a href="#获取响应内容">获取响应内容</a></li>
<li><a href="#根据上述内容整合">根据上述内容整合</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>\10. Elasticsearch JAVA API 的学习使用<ul>
<li>10.1 起步：<ul>
<li><a href="#1011-maven-依赖">10.1.1 Maven 依赖</a></li>
</ul>
</li>
</ul>
</li>
<li>\11. Es painless 脚本插件使用（Elasticsearch script plugin）<ul>
<li>11.1 前置条件：windows安装gradle<ul>
<li><a href="#1111-官方下载地址">11.1.1 官方下载地址</a></li>
<li><a href="#1112-将gradle放入合适位置将gradle加入path环境变量">11.1.2 将gradle放入合适位置，将gradle加入path环境变量</a></li>
<li><a href="#1113-配置阿里云的镜像">11.1.3 配置阿里云的镜像</a></li>
</ul>
</li>
</ul>
</li>
<li>N kibana 学习es的所有内容<ul>
<li><a href="#20191014">2019.10.14</a></li>
<li><a href="#20191015">2019.10.15</a></li>
</ul>
</li>
</ul>
<h1 id="官方改变1"><a href="#官方改变1" class="headerlink" title="官方改变1"></a>官方改变1</h1><h2 id="RestFul请求需要加入Header"><a href="#RestFul请求需要加入Header" class="headerlink" title="RestFul请求需要加入Header"></a>RestFul请求需要加入Header</h2><blockquote>
<p>-H “Content-Type: application/json”</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -H &quot;Content-Type: application&#x2F;json&quot; -XPUT &#39;localhost:9200&#x2F;get-together&#x2F;group&#x2F;1?pretty&#39; -d &#39;&#123;&quot;name&quot;:&quot;elastice denver&quot;,&quot;organizer&quot;:&quot;Lee&quot;&#125;&#39;</span><br></pre></td></tr></table></figure>

<h1 id="官方改变2："><a href="#官方改变2：" class="headerlink" title="官方改变2："></a>官方改变2：</h1><h2 id="分词器-N元语法ngram"><a href="#分词器-N元语法ngram" class="headerlink" title="分词器 N元语法ngram"></a>分词器 N元语法ngram</h2><p>分词器 N元语法ngram 由于在实际使用发生过巨大差异事故，在6.2.4 提示是被弃用的，但是后面社区提议在实际需求中使用发现没有效果，与开发交流过后，官方在7.0之后将弃用删除，继续使用ngram</p>
<blockquote>
<p>所以在这个6.2.4 版本中使用ngram 分词器 的参数 min_gram 和 max_gram 无法作用于N元语法</p>
</blockquote>
<h1 id="1-基本使用"><a href="#1-基本使用" class="headerlink" title="1. 基本使用"></a>1. 基本使用</h1><h2 id="1-1-创建索引"><a href="#1-1-创建索引" class="headerlink" title="1.1 创建索引"></a>1.1 创建索引</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;lib&#x2F;</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">  &quot;settings&quot;:&#123;</span><br><span class="line"></span><br><span class="line">      &quot;index&quot;:&#123;</span><br><span class="line"></span><br><span class="line">        &quot;number_of_shards&quot;: 5,</span><br><span class="line"></span><br><span class="line">        &quot;number_of_replicas&quot;: 1</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="1-2-查看索引信息"><a href="#1-2-查看索引信息" class="headerlink" title="1.2 查看索引信息:"></a>1.2 查看索引信息:</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_settings</span><br><span class="line">curl -XGET &#39;192.168.92.180:9200&#x2F;lib&#x2F;_settings?pretty&#39;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;lib&quot; : &#123;</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">      &quot;index&quot; : &#123;</span><br><span class="line">        &quot;creation_date&quot; : &quot;1570895449310&quot;,</span><br><span class="line">        &quot;number_of_shards&quot; : &quot;5&quot;,</span><br><span class="line">        &quot;number_of_replicas&quot; : &quot;1&quot;,</span><br><span class="line">        &quot;uuid&quot; : &quot;KF8Kfs3SSBKPhZX4pX5iVw&quot;,</span><br><span class="line">        &quot;version&quot; : &#123;</span><br><span class="line">          &quot;created&quot; : &quot;6020499&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;provided_name&quot; : &quot;lib&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">GET _all&#x2F;_settings</span><br><span class="line">curl -XGET &#39;192.168.92.180:9200&#x2F;_all&#x2F;_settings?pretty&#39;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;new-index&quot; : &#123;</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">      &quot;index&quot; : &#123;</span><br><span class="line">        &quot;creation_date&quot; : &quot;1570877785070&quot;,</span><br><span class="line">        &quot;number_of_shards&quot; : &quot;5&quot;,</span><br><span class="line">        &quot;number_of_replicas&quot; : &quot;1&quot;,</span><br><span class="line">        &quot;uuid&quot; : &quot;0HE2lh_gS96UPRCIWMqaZA&quot;,</span><br><span class="line">        &quot;version&quot; : &#123;</span><br><span class="line">          &quot;created&quot; : &quot;6020499&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;provided_name&quot; : &quot;new-index&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;get-together&quot; : &#123;</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">      &quot;index&quot; : &#123;</span><br><span class="line">        &quot;creation_date&quot; : &quot;1570878100116&quot;,</span><br><span class="line">        &quot;number_of_shards&quot; : &quot;5&quot;,</span><br><span class="line">        &quot;number_of_replicas&quot; : &quot;1&quot;,</span><br><span class="line">        &quot;uuid&quot; : &quot;t1a2Kwx-QvCjF-pSuTGntQ&quot;,</span><br><span class="line">        &quot;version&quot; : &#123;</span><br><span class="line">          &quot;created&quot; : &quot;6020499&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;provided_name&quot; : &quot;get-together&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;lib&quot; : &#123;</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">      &quot;index&quot; : &#123;</span><br><span class="line">        &quot;creation_date&quot; : &quot;1570895449310&quot;,</span><br><span class="line">        &quot;number_of_shards&quot; : &quot;5&quot;,</span><br><span class="line">        &quot;number_of_replicas&quot; : &quot;1&quot;,</span><br><span class="line">        &quot;uuid&quot; : &quot;KF8Kfs3SSBKPhZX4pX5iVw&quot;,</span><br><span class="line">        &quot;version&quot; : &#123;</span><br><span class="line">          &quot;created&quot; : &quot;6020499&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;provided_name&quot; : &quot;lib&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="1-3-创建类型"><a href="#1-3-创建类型" class="headerlink" title="1.3 创建类型"></a>1.3 创建类型</h2><h3 id="1-3-2-指定id的方式："><a href="#1-3-2-指定id的方式：" class="headerlink" title="1.3.2 指定id的方式："></a>1.3.2 指定id的方式：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;lib&#x2F;user&#x2F;2</span><br><span class="line">&#123;</span><br><span class="line">  &quot;first_name&quot;: &quot;book&quot;,</span><br><span class="line">  &quot;last_name&quot;: &quot;lin lin&quot;,</span><br><span class="line">  &quot;age&quot;: 20,</span><br><span class="line">  &quot;birthday&quot;: &quot;2019-4-28&quot;,</span><br><span class="line">  &quot;interesting&quot;: [</span><br><span class="line">    &quot;football&quot;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="1-3-1-不指定id的方式"><a href="#1-3-1-不指定id的方式" class="headerlink" title="1.3.1 不指定id的方式"></a>1.3.1 不指定id的方式</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;user&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">    &quot;first_name&quot;: &quot;book&quot;,</span><br><span class="line">  &quot;last_name&quot;: &quot;lin lin&quot;,</span><br><span class="line">  &quot;age&quot;: 20,</span><br><span class="line">  &quot;birthday&quot;: &quot;20191122&quot;,</span><br><span class="line">  &quot;interesting&quot;: [ &quot;football&quot;]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;lib&#x2F;user&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">    &quot;first_name&quot; :  &quot;Douglas&quot;,</span><br><span class="line">    &quot;last_name&quot; :   &quot;Fir&quot;,</span><br><span class="line">    &quot;age&quot; :         23,</span><br><span class="line">    &quot;about&quot;:        &quot;I like to build cabinets&quot;,</span><br><span class="line">    &quot;interests&quot;:  [ &quot;forestry&quot; ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="1-4-创建一个文档"><a href="#1-4-创建一个文档" class="headerlink" title="1.4 创建一个文档"></a>1.4 创建一个文档</h2><p>当使用curl 的时候， 他看上去是这样的</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">curl -H &quot;Content-Type: application&#x2F;json&quot; -XPUT &#39;192.168.92.180:9200&#x2F;lib&#x2F;user&#x2F;1&#39; -d \</span><br><span class="line">&gt; &#39;&#123;</span><br><span class="line">&gt; &quot;first_name&quot;:&quot;Jane&quot;,</span><br><span class="line">&gt; &quot;last_name&quot;:&quot;Smith&quot;,</span><br><span class="line">&gt; &quot;age&quot;:32,</span><br><span class="line">&gt; &quot;about&quot;:&quot;I like to collect rock albums&quot;,</span><br><span class="line">&gt; &quot;interests&quot;: [&quot;music&quot;]</span><br><span class="line">&gt; &#125;&#39;</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">	&quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">	&quot;_id&quot;: &quot;1&quot;,</span><br><span class="line">	&quot;_version&quot;: 1,</span><br><span class="line">	&quot;result&quot;: &quot;created&quot;,</span><br><span class="line">	&quot;_shards&quot;: &#123;</span><br><span class="line">		&quot;total&quot;: 2,</span><br><span class="line">		&quot;successful&quot;: 1,</span><br><span class="line">		&quot;failed&quot;: 0</span><br><span class="line">	&#125;,</span><br><span class="line">	&quot;_seq_no&quot;: 0,</span><br><span class="line">	&quot;_primary_term&quot;: 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="2-基础搜索"><a href="#2-基础搜索" class="headerlink" title="2. 基础搜索"></a>2. 基础搜索</h1><h2 id="2-1-使用query-进行搜索"><a href="#2-1-使用query-进行搜索" class="headerlink" title="2.1 使用query 进行搜索"></a>2.1 使用query 进行搜索</h2><h3 id="原始方式"><a href="#原始方式" class="headerlink" title="原始方式"></a>原始方式</h3><p>curl -H “Content-Type: application/json”</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">curl -H &quot;Content-Type: application&#x2F;json&quot; -XGET &#39;119.23.219.183:9200&#x2F;lib&#x2F;user&#x2F;_search?pretty&#39; -d &#39;&#123;&quot;query&quot;:&#123;“defualt”: &quot;field_name&quot;, &quot;query_string&quot;: &#123;&quot;query&quot;: &quot;jone&quot;&#125;&#125;&#125;&#39;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;took&quot; : 11,</span><br><span class="line">  &quot;timed_out&quot; : false,</span><br><span class="line">  &quot;_shards&quot; : &#123;</span><br><span class="line">    &quot;total&quot; : 5,</span><br><span class="line">    &quot;successful&quot; : 5,</span><br><span class="line">    &quot;skipped&quot; : 0,</span><br><span class="line">    &quot;failed&quot; : 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot; : &#123;</span><br><span class="line">    &quot;total&quot; : 1,</span><br><span class="line">    &quot;max_score&quot; : 0.2876821,</span><br><span class="line">    &quot;hits&quot; : [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot; : &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot; : &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot; : &quot;1&quot;,</span><br><span class="line">        &quot;_score&quot; : 0.2876821,</span><br><span class="line">        &quot;_source&quot; : &#123;</span><br><span class="line">          &quot;first_name&quot; : &quot;Jone&quot;,</span><br><span class="line">          &quot;last_name&quot; : &quot;pig&quot;,</span><br><span class="line">          &quot;age&quot; : 11,</span><br><span class="line">          &quot;birthday&quot; : &quot;2019-11-18&quot;,</span><br><span class="line">          &quot;interesting&quot; : [</span><br><span class="line">            &quot;basketball&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="kibana方式"><a href="#kibana方式" class="headerlink" title="kibana方式"></a>kibana方式</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search?pretty </span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;:&#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      “defualt”: &quot;field_name&quot;</span><br><span class="line">      &quot;query&quot;: &quot;jone&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="2-1-1-如果只想查找一个字段，可以使用term"><a href="#2-1-1-如果只想查找一个字段，可以使用term" class="headerlink" title="2.1.1 如果只想查找一个字段，可以使用term"></a>2.1.1 如果只想查找一个字段，可以使用term</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search?pretty </span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;:&#123;</span><br><span class="line">    &quot;term&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &quot;jone&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="2-2-过滤器"><a href="#2-2-过滤器" class="headerlink" title="2.2 过滤器"></a>2.2 过滤器</h2><h3 id="2-2-1-ES6以下："><a href="#2-2-1-ES6以下：" class="headerlink" title="2.2.1 ES6以下："></a>2.2.1 ES6以下：</h3><p>旧版本使用如下方式 <strong>es6版本以下</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;:&#123;</span><br><span class="line">    &quot;filtered&quot;:&#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;term&quot;:&#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;jone&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-2-2-ES6及以上："><a href="#2-2-2-ES6及以上：" class="headerlink" title="2.2.2 ES6及以上："></a>2.2.2 ES6及以上：</h3><p>新版本的过滤器要使用如下方式</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;:&#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;jone&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="2-3-应用聚集"><a href="#2-3-应用聚集" class="headerlink" title="2.3 应用聚集"></a>2.3 应用聚集</h2><h3 id="2-3-1-ES6以下："><a href="#2-3-1-ES6以下：" class="headerlink" title="2.3.1 ES6以下："></a>2.3.1 ES6以下：</h3><p>旧版本使用如下方式 <strong>es6版本以下</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">	&quot;aggregations&quot;:&#123;</span><br><span class="line">		&quot;organizers&quot;:&#123;</span><br><span class="line">			&quot;terms&quot;: &#123; &quot;field&quot; : &quot;organizer&quot; &#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-3-2-ES6及以上："><a href="#2-3-2-ES6及以上：" class="headerlink" title="2.3.2 ES6及以上："></a>2.3.2 ES6及以上：</h3><p>需求是根据年龄进行划分聚合</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;size&quot;: 0, </span><br><span class="line">  &quot;aggs&quot;: &#123;</span><br><span class="line">    </span><br><span class="line">    &quot;organizers&quot;:&#123;</span><br><span class="line">      &quot;terms&quot;: &#123;</span><br><span class="line">        &quot;field&quot;: &quot;age&quot;,</span><br><span class="line">        &quot;size&quot;: 10</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>（1）size</strong>：查询条数，这里设置为0，因为不关心搜索到的结果，只关心聚合结果，提供效率；</p>
<p><strong>（2）aggs</strong>：声明这是一个聚合查询，是aggregations的缩写；</p>
<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;took&quot;: 47,</span><br><span class="line">  &quot;timed_out&quot;: false,</span><br><span class="line">  &quot;_shards&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 5,</span><br><span class="line">    &quot;successful&quot;: 5,</span><br><span class="line">    &quot;skipped&quot;: 0,</span><br><span class="line">    &quot;failed&quot;: 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 3,</span><br><span class="line">    &quot;max_score&quot;: 0,</span><br><span class="line">    &quot;hits&quot;: []</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;aggregations&quot;: &#123;</span><br><span class="line">    &quot;organizers&quot;: &#123;</span><br><span class="line">      &quot;doc_count_error_upper_bound&quot;: 0,</span><br><span class="line">      &quot;sum_other_doc_count&quot;: 0,</span><br><span class="line">      &quot;buckets&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;key&quot;: 11,</span><br><span class="line">          &quot;doc_count&quot;: 1</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;key&quot;: 20,</span><br><span class="line">          &quot;doc_count&quot;: 1</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;key&quot;: 23,</span><br><span class="line">          &quot;doc_count&quot;: 1</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="2-4-通过Id获取文档"><a href="#2-4-通过Id获取文档" class="headerlink" title="2.4 通过Id获取文档"></a>2.4 通过Id获取文档</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;1</span><br></pre></td></tr></table></figure>

<h1 id="3-elasticsearch配置"><a href="#3-elasticsearch配置" class="headerlink" title="3. elasticsearch配置"></a>3. elasticsearch配置</h1><h2 id="3-1-指定集群名称："><a href="#3-1-指定集群名称：" class="headerlink" title="3.1 指定集群名称："></a>3.1 指定集群名称：</h2><p>在<strong>elasticsearch.yml</strong> 文件当中指定</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cluster.name: xxxx</span><br></pre></td></tr></table></figure>

<h2 id="3-2-指定详细的日志记录"><a href="#3-2-指定详细的日志记录" class="headerlink" title="3.2 指定详细的日志记录"></a>3.2 指定详细的日志记录</h2><ol>
<li><p>主要日志</p>
<p>基础的日志</p>
</li>
<li><p>慢搜索日志</p>
<p>多于半秒的查询都会被记录（默认）</p>
</li>
<li><p>慢索引日志</p>
<p>多于半秒的查询都会被记录（默认）</p>
</li>
</ol>
<p>在<strong>elasticsearch.yml</strong> 文件当中指定,查看所有的日志</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rootLogger: TRACE, console, file</span><br></pre></td></tr></table></figure>

<h2 id="3-3-调整虚拟机大小"><a href="#3-3-调整虚拟机大小" class="headerlink" title="3.3 调整虚拟机大小"></a>3.3 调整虚拟机大小</h2><h3 id="3-3-1-linux-使用如下命令："><a href="#3-3-1-linux-使用如下命令：" class="headerlink" title="3.3.1 linux 使用如下命令："></a>3.3.1 linux 使用如下命令：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">export ES_HEAP_SIZE&#x3D;500m bin&#x2F;elasticsearch</span><br></pre></td></tr></table></figure>

<h3 id="3-3-2-使用elasticsearch-yml修改启动堆内存大小"><a href="#3-3-2-使用elasticsearch-yml修改启动堆内存大小" class="headerlink" title="3.3.2 使用elasticsearch.yml修改启动堆内存大小"></a>3.3.2 使用elasticsearch.yml修改启动堆内存大小</h3><h3 id="3-3-3-使用修改bin-elasticsearch-in-sh-修改"><a href="#3-3-3-使用修改bin-elasticsearch-in-sh-修改" class="headerlink" title="3.3.3 使用修改bin/elasticsearch.in.sh 修改"></a>3.3.3 使用修改bin/elasticsearch.in.sh 修改</h3><p>#!/bin/sh 后面加入ES_HEAP_SIZE=500m</p>
<h2 id="3-4-集群中加入节点"><a href="#3-4-集群中加入节点" class="headerlink" title="3.4 集群中加入节点"></a>3.4 集群中加入节点</h2><h3 id="3-4-1-查看节点状态"><a href="#3-4-1-查看节点状态" class="headerlink" title="3.4.1 查看节点状态"></a>3.4.1 查看节点状态</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET _cat&#x2F;shards?v</span><br></pre></td></tr></table></figure>

<h1 id="4-映射-mapping"><a href="#4-映射-mapping" class="headerlink" title="4. 映射_mapping"></a>4. 映射_mapping</h1><p>使用映射来定义文档：</p>
<p>注意同一个索引存在多个类型，所有映射也可以多个类型</p>
<p>但是多个类型可能存在文档里面相同名称的字段</p>
<h2 id="4-1-检索和自定义映射"><a href="#4-1-检索和自定义映射" class="headerlink" title="4.1 检索和自定义映射"></a>4.1 检索和自定义映射</h2><h3 id="4-1-1-获取目前的映射"><a href="#4-1-1-获取目前的映射" class="headerlink" title="4.1.1 获取目前的映射"></a>4.1.1 获取目前的映射</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_mapping?pretty</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;lib&quot;: &#123;</span><br><span class="line">    &quot;mappings&quot;: &#123;</span><br><span class="line">      &quot;user&quot;: &#123;</span><br><span class="line">        &quot;properties&quot;: &#123;</span><br><span class="line">          &quot;about&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">            &quot;fields&quot;: &#123;</span><br><span class="line">              &quot;keyword&quot;: &#123;</span><br><span class="line">                &quot;type&quot;: &quot;keyword&quot;,</span><br><span class="line">                &quot;ignore_above&quot;: 256</span><br><span class="line">              &#125;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;age&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;long&quot;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;birthday&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;date&quot;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;first_name&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">            &quot;fields&quot;: &#123;</span><br><span class="line">              &quot;keyword&quot;: &#123;</span><br><span class="line">                &quot;type&quot;: &quot;keyword&quot;,</span><br><span class="line">                &quot;ignore_above&quot;: 256</span><br><span class="line">              &#125;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;interesting&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">            &quot;fields&quot;: &#123;</span><br><span class="line">              &quot;keyword&quot;: &#123;</span><br><span class="line">                &quot;type&quot;: &quot;keyword&quot;,</span><br><span class="line">                &quot;ignore_above&quot;: 256</span><br><span class="line">              &#125;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;interests&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">            &quot;fields&quot;: &#123;</span><br><span class="line">              &quot;keyword&quot;: &#123;</span><br><span class="line">                &quot;type&quot;: &quot;keyword&quot;,</span><br><span class="line">                &quot;ignore_above&quot;: 256</span><br><span class="line">              &#125;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;last_name&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">            &quot;fields&quot;: &#123;</span><br><span class="line">              &quot;keyword&quot;: &#123;</span><br><span class="line">                &quot;type&quot;: &quot;keyword&quot;,</span><br><span class="line">                &quot;ignore_above&quot;: 256</span><br><span class="line">              &#125;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="4-1-2-获取自动生成的映射"><a href="#4-1-2-获取自动生成的映射" class="headerlink" title="4.1.2 获取自动生成的映射"></a>4.1.2 获取自动生成的映射</h3><p>使用下面的实例：</p>
<p>第一步：创建一个新索引</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;get-together&#x2F;new-event&#x2F;1</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;:&quot;late night with elastic&quot;,</span><br><span class="line">  &quot;date&quot;:&quot;2013-10-25T19:00&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>第二步： 获取当前映射</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;get-together&#x2F;_mapping&#x2F;new-event?pretty</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;get-together&quot;: &#123;</span><br><span class="line">    &quot;mappings&quot;: &#123;</span><br><span class="line">      &quot;new-event&quot;: &#123;</span><br><span class="line">        &quot;properties&quot;: &#123;</span><br><span class="line">          &quot;date&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;date&quot;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;name&quot;: &#123;</span><br><span class="line">            &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">            &quot;fields&quot;: &#123;</span><br><span class="line">              &quot;keyword&quot;: &#123;</span><br><span class="line">                &quot;type&quot;: &quot;keyword&quot;,</span><br><span class="line">                &quot;ignore_above&quot;: 256</span><br><span class="line">              &#125;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="4-1-3-定义新的映射"><a href="#4-1-3-定义新的映射" class="headerlink" title="4.1.3 定义新的映射"></a>4.1.3 定义新的映射</h3><h4 id="es6以下版本"><a href="#es6以下版本" class="headerlink" title="es6以下版本"></a>es6以下版本</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;get-together&#x2F;_mapping&#x2F;new-event</span><br><span class="line">&#123;</span><br><span class="line">  &quot;new-event&quot;:&#123;</span><br><span class="line">    &quot;properties&quot;:&#123;</span><br><span class="line">      &quot;host&quot;: &#123;</span><br><span class="line">        &quot;type&quot;: &quot;string&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="es6以上版本"><a href="#es6以上版本" class="headerlink" title="es6以上版本"></a>es6以上版本</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;get-together&#x2F;_mapping&#x2F;new-event</span><br><span class="line">&#123;</span><br><span class="line">  &quot;properties&quot;: &#123;</span><br><span class="line">    &quot;host&quot;:&#123;</span><br><span class="line">      &quot;type&quot;: &quot;keyword&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>此时获取映射会发现新增了一个映射内容</p>
<h3 id="4-1-4-改变现有字段类型的方法："><a href="#4-1-4-改变现有字段类型的方法：" class="headerlink" title="4.1.4 改变现有字段类型的方法："></a>4.1.4 改变现有字段类型的方法：</h3><ol>
<li>删除 new-evenets 类型的所有数据</li>
<li>设置新的映射类型以及字段类型</li>
<li>再次索引所有数据</li>
</ol>
<h2 id="4-2-用于定义文档字段的核心类型"><a href="#4-2-用于定义文档字段的核心类型" class="headerlink" title="4.2 用于定义文档字段的核心类型"></a>4.2 用于定义文档字段的核心类型</h2><h3 id="4-2-1-定义映射当中的index选项"><a href="#4-2-1-定义映射当中的index选项" class="headerlink" title="4.2.1 定义映射当中的index选项"></a>4.2.1 定义映射当中的index选项</h3><ol>
<li>anaLyzed(默认) 将大写转为小写，字符串分解为单词</li>
<li>not_analyzed 分析过程略过，变成单独的词条索引</li>
<li>no 索引略过，没有词条产生<ol>
<li>节省存储空间，无须在该字段搜索的时候使用</li>
</ol>
</li>
</ol>
<h3 id="4-2-2-如何创建嵌套类型："><a href="#4-2-2-如何创建嵌套类型：" class="headerlink" title="4.2.2 如何创建嵌套类型："></a>4.2.2 如何创建嵌套类型：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;get-together&#x2F;_mapping&#x2F;new-event</span><br><span class="line">&#123;</span><br><span class="line">  &quot;properties&quot;: &#123;</span><br><span class="line">    &quot;test&quot;: &#123;</span><br><span class="line">      &quot;type&quot;: &quot;text&quot;</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;user&quot;:&#123;</span><br><span class="line">      &quot;type&quot;: &quot;nested&quot;,</span><br><span class="line">      &quot;properties&quot;: &#123;</span><br><span class="line">        &quot;myname&quot;:&#123;</span><br><span class="line">          &quot;type&quot;:&quot;text&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="4-2-3-定义多字段和数组类型"><a href="#4-2-3-定义多字段和数组类型" class="headerlink" title="4.2.3 定义多字段和数组类型"></a>4.2.3 定义多字段和数组类型</h3><h2 id="4-3-使用预定义字段"><a href="#4-3-使用预定义字段" class="headerlink" title="4.3 使用预定义字段"></a>4.3 使用预定义字段</h2><h3 id="4-3-1-控制如何存储和搜索文档"><a href="#4-3-1-控制如何存储和搜索文档" class="headerlink" title="4.3.1 控制如何存储和搜索文档"></a>4.3.1 控制如何存储和搜索文档</h3><ol>
<li><p>_source 存储原有内容</p>
<ol>
<li>按照原有格式存储原有文档</li>
<li>enable可以设置true,false</li>
<li>返回某些特定字段在url指定使用fields=xxx,如果需要多个字段用逗号隔开</li>
<li>使用”store”: “yes” 存储特定的字段</li>
</ol>
</li>
<li><p>_all 索引一切</p>
<ol>
<li>不指定字段名称默认是_all查找</li>
<li>默认隐藏属性为”<strong>include_in_all</strong>“ ， 可以设置为false不被包含</li>
</ol>
</li>
<li><p>_uid 识别文档</p>
<ol>
<li>_type和_id的结合体</li>
<li>es内部使用_uid 来确定唯一文档的身份</li>
</ol>
</li>
<li><p>_index 在文档中存储索引名称</p>
<ol>
<li>默认情况下是关闭的</li>
<li>如果需要了解其内容，需要实现使用put 请求将enabled 设置为true</li>
</ol>
</li>
<li><p>_update 更新现有文档</p>
<ol>
<li>默认使用go语言进行脚本的更新操作</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;user&#x2F;1&#x2F;_update</span><br><span class="line">&#123;</span><br><span class="line">  &quot;doc&quot;: &#123;</span><br><span class="line">    &quot;first_name&quot;:&quot;sss&quot;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>upsert 创建不存在的文档（注意此时5不存在）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;user&#x2F;5&#x2F;_update</span><br><span class="line">&#123;</span><br><span class="line">  &quot;doc&quot;:&#123;</span><br><span class="line">    &quot;age&quot;:5</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;upsert&quot;: &#123;</span><br><span class="line">    &quot;myname&quot;: &quot;elastic&quot;,</span><br><span class="line">    &quot;age&quot;: 4</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>_open 以及 _close 分别表示开放索引和关闭索引</p>
</li>
</ol>
<h2 id="4-4-更新现有文档"><a href="#4-4-更新现有文档" class="headerlink" title="4.4 更新现有文档"></a>4.4 更新现有文档</h2><h3 id="4-4-1-文档更新包含如下步骤："><a href="#4-4-1-文档更新包含如下步骤：" class="headerlink" title="4.4.1 文档更新包含如下步骤："></a>4.4.1 文档更新包含如下步骤：</h3><ol>
<li>检索文档</li>
<li>处理文档</li>
<li>重新索引文档</li>
<li>先前文档被删除</li>
<li>完成</li>
</ol>
<h2 id="4-5-删除文档"><a href="#4-5-删除文档" class="headerlink" title="4.5 删除文档"></a>4.5 删除文档</h2><h3 id="4-5-1-删除文档的方式"><a href="#4-5-1-删除文档的方式" class="headerlink" title="4.5.1 删除文档的方式"></a>4.5.1 删除文档的方式</h3><ol>
<li>删除单个文档或者一组文档<ol>
<li>标记为删除</li>
<li>延迟用异步方式排出</li>
</ol>
</li>
<li>删除整个索引（删除多组文档的特例）<ol>
<li>移除和索引所有相关的文件</li>
<li>效率高</li>
</ol>
</li>
<li>关闭索引<ol>
<li>不允许读写操作，数据也不进内存</li>
<li>但是索引还是在磁盘内</li>
<li>可以再次打开关闭的索引</li>
</ol>
</li>
</ol>
<h3 id="4-5-2-删除文档"><a href="#4-5-2-删除文档" class="headerlink" title="4.5.2 删除文档"></a>4.5.2 删除文档</h3><ol>
<li>通过id删除单个文档</li>
<li>单个请求删除多个文档<ol>
<li>比单独删除效率高</li>
</ol>
</li>
<li>删除映射类型，包括其中文档</li>
<li>删除匹配某个查询的所有文档</li>
</ol>
<h3 id="4-5-3-删除单个文档"><a href="#4-5-3-删除单个文档" class="headerlink" title="4.5.3 删除单个文档"></a>4.5.3 删除单个文档</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DELETE &#x2F;lib&#x2F;user&#x2F;5</span><br></pre></td></tr></table></figure>

<p>为了防止外部的并发更新与删除的操作：</p>
<p>es在一段时间内保留这篇文档的版本，拒绝比删除文档更低的更新操作</p>
<p>默认时间为60秒</p>
<p>yml或者索引配置的 <strong>index.gc_deletes</strong> 设置保留时间</p>
<h3 id="4-5-4-删除映射类型和删除查询匹配的文档"><a href="#4-5-4-删除映射类型和删除查询匹配的文档" class="headerlink" title="4.5.4 删除映射类型和删除查询匹配的文档"></a>4.5.4 删除映射类型和删除查询匹配的文档</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DELETE &#x2F;get-together&#x2F;_query?q&#x3D;elasticsearch</span><br></pre></td></tr></table></figure>

<p>注意点：</p>
<ol>
<li>类型名称只是文档的另一个字段</li>
<li>索引的所有文档，无论属于哪个映射类型，都存在同一个分片</li>
<li><strong>针对删除类型和删除完整索引两者的性能进行比较的时候，删除类型比删除索引要更长的时间和更多的资源</strong></li>
</ol>
<h3 id="4-5-5-删除索引"><a href="#4-5-5-删除索引" class="headerlink" title="4.5.5 删除索引"></a>4.5.5 删除索引</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">DELETE &#x2F;myindex[,xxx,xx] 删除一个或者多个索引</span><br><span class="line">DELETE &#x2F;_all 删除所有的索引</span><br></pre></td></tr></table></figure>

<blockquote>
<p>_all 删除所有文档是否过于危险？</p>
<p>elasticsearch.yml 文件中</p>
<p>action.destructive_requires_name: true</p>
<p>预防这种情况发生， 可以<strong>拒绝</strong>delete _all 操作</p>
<p>以及索引名称当中的<strong>通配符</strong></p>
</blockquote>
<p>注意这里的删除也是标记删除：在分段与合并中进行合并之后才会真实删除操作</p>
<blockquote>
<p>分段与合并是什么？</p>
<ol>
<li>一个分段是建立索引的时候创建的一块Lucene 索引</li>
<li>当es在分片上查询的时候，Luncene需要查询所有的分段</li>
<li>合并文档意味着分段的合并以及I/O和CPU读写操作（合并操作是异步进行的）</li>
<li>索引操作会产生许多小分段，需要定期进行合并</li>
</ol>
</blockquote>
<h3 id="4-5-6-关闭和开发索引"><a href="#4-5-6-关闭和开发索引" class="headerlink" title="4.5.6 关闭和开发索引"></a>4.5.6 关闭和开发索引</h3><p>使用POST 加上 _open 以及 _close 对于索引进行开放和关闭</p>
<ol>
<li>一旦索引被关闭，内存唯一痕迹是元数据，如名字以及分片的位置</li>
<li>如果条件允许，关闭索引比删除索引要好</li>
</ol>
<h1 id="5-版本控制"><a href="#5-版本控制" class="headerlink" title="5. 版本控制"></a>5. 版本控制</h1><h2 id="5-1-乐观锁"><a href="#5-1-乐观锁" class="headerlink" title="5.1 乐观锁"></a>5.1 乐观锁</h2><h3 id="5-1-1-内部版本控制"><a href="#5-1-1-内部版本控制" class="headerlink" title="5.1.1 内部版本控制"></a>5.1.1 内部版本控制</h3><p>PUT /lib/user/4?version=3</p>
<h3 id="5-1-2-外部版本控制"><a href="#5-1-2-外部版本控制" class="headerlink" title="5.1.2 外部版本控制"></a>5.1.2 外部版本控制</h3><p>version_type=external + 版本号</p>
<h2 id="5-2-自动重试"><a href="#5-2-自动重试" class="headerlink" title="5.2 自动重试"></a>5.2 自动重试</h2><p>retry_on_conflict=3(版本号) 自动重试</p>
<h1 id="6-搜索与高级搜索分析"><a href="#6-搜索与高级搜索分析" class="headerlink" title="6. 搜索与高级搜索分析"></a>6. 搜索与高级搜索分析</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">curl &#39;&#x2F;_search&#39;</span><br><span class="line">curl &#39;&#x2F;xxx&#x2F;_search&#39; 指定索引</span><br><span class="line">curl &#39;&#x2F;xxx&#x2F;xxx&#x2F;_search&#39; 搜索类型</span><br><span class="line">curl &#39;&#x2F;_all&#x2F;xxx&#x2F;_search&#39; 所有索引中搜索时事件类型</span><br><span class="line">curl &#39;&#x2F;*&#x2F;xxx&#x2F;_search&#39; 通配符搜索所有</span><br><span class="line">curl &#39;&#x2F;xxxx,xxxx&#x2F;xxx,xxxx&#x2F;_search&#39; 多个类型搜索</span><br><span class="line">curl &#39;&#x2F;+get-toge*,-get-together&#x2F;_search&#39; 搜索以get-toge 开头的索引，但是不包括get-together</span><br></pre></td></tr></table></figure>

<h2 id="6-1-搜索请求的基本模块"><a href="#6-1-搜索请求的基本模块" class="headerlink" title="6.1 搜索请求的基本模块"></a>6.1 搜索请求的基本模块</h2><ol>
<li>query：搜索请求最重要的部分，配置了基于评分返回最佳的文档</li>
<li>size：代表返回文档数量</li>
<li>from：和size一起使用，用于分页操作（注意：为了知道第二页的10项结果，必须先知道计算前20的结果，也就是说，<strong>越往后的翻页搜索代价越大</strong>）</li>
<li>_source：指定字段如何返回</li>
<li>sort：默认排序基于文档得分</li>
</ol>
<h2 id="6-2-基于url的搜索请求"><a href="#6-2-基于url的搜索请求" class="headerlink" title="6.2 基于url的搜索请求"></a>6.2 基于url的搜索请求</h2><h3 id="6-2-1-基于from-和szize的参数来实现结果分页"><a href="#6-2-1-基于from-和szize的参数来实现结果分页" class="headerlink" title="6.2.1 基于from 和szize的参数来实现结果分页"></a>6.2.1 基于from 和szize的参数来实现结果分页</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search?from&#x3D;2&amp;size&#x3D;2</span><br></pre></td></tr></table></figure>

<p>from=2 表示从第三条开始</p>
<p>size=2 表示读取2条记录</p>
<h3 id="6-2-2-改变结果的顺序"><a href="#6-2-2-改变结果的顺序" class="headerlink" title="6.2.2 改变结果的顺序"></a>6.2.2 改变结果的顺序</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_search?sort&#x3D;age:_id</span><br></pre></td></tr></table></figure>

<h3 id="6-2-3-搜索结果当中限制-source-字段"><a href="#6-2-3-搜索结果当中限制-source-字段" class="headerlink" title="6.2.3 搜索结果当中限制_source 字段"></a>6.2.3 搜索结果当中限制_source 字段</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_search?sort&#x3D;age:_id&amp;_source&#x3D;first_name,age</span><br></pre></td></tr></table></figure>

<h3 id="6-2-4-匹配查询"><a href="#6-2-4-匹配查询" class="headerlink" title="6.2.4 匹配查询"></a>6.2.4 匹配查询</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_search?sort&#x3D;age:_id&amp;_source&#x3D;first_name,age</span><br></pre></td></tr></table></figure>

<h2 id="6-3-基于请求主体的搜索请求"><a href="#6-3-基于请求主体的搜索请求" class="headerlink" title="6.3 基于请求主体的搜索请求"></a>6.3 基于请求主体的搜索请求</h2><h3 id="6-3-1-使用from-和-size，参数结果分页"><a href="#6-3-1-使用from-和-size，参数结果分页" class="headerlink" title="6.3.1 使用from 和 size，参数结果分页"></a>6.3.1 使用from 和 size，参数结果分页</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;size&quot;: 2,</span><br><span class="line">  &quot;from&quot;: 2</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="6-3-2-过滤返回-source-内容"><a href="#6-3-2-过滤返回-source-内容" class="headerlink" title="6.3.2 过滤返回_source 内容"></a>6.3.2 过滤返回_source 内容</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;_source&quot;: [&quot;first_name&quot;, &quot;age&quot;]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="在source字段当中返回通配符"><a href="#在source字段当中返回通配符" class="headerlink" title="在source字段当中返回通配符"></a>在source字段当中返回通配符</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;_source&quot;: [&quot;*_name&quot;, &quot;a*&quot;]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如果是数组，可以指定: _source: [“name.*”, “address.*”]</p>
<h4 id="通过include以及exclude-过滤返回-source的内容"><a href="#通过include以及exclude-过滤返回-source的内容" class="headerlink" title="通过include以及exclude 过滤返回_source的内容"></a>通过include以及exclude 过滤返回_source的内容</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;_source&quot;: &#123;</span><br><span class="line">    &quot;includes&quot;: [&quot;*_name&quot;, &quot;age&quot;],</span><br><span class="line">    &quot;excludes&quot;: [&quot;first_name&quot;]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>include: 包含匹配</p>
<p>excludes: 排除</p>
<h3 id="6-3-3-基于结果的排序"><a href="#6-3-3-基于结果的排序" class="headerlink" title="6.3.3 基于结果的排序"></a>6.3.3 基于结果的排序</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;sort&quot;: [</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;age&quot;: &#123;</span><br><span class="line">        &quot;order&quot;: &quot;desc&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line"> </span><br><span class="line">    &quot;_score&quot;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;took&quot;: 12,</span><br><span class="line">  &quot;timed_out&quot;: false,</span><br><span class="line">  &quot;_shards&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 5,</span><br><span class="line">    &quot;successful&quot;: 5,</span><br><span class="line">    &quot;skipped&quot;: 0,</span><br><span class="line">    &quot;failed&quot;: 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 15,</span><br><span class="line">    &quot;max_score&quot;: null,</span><br><span class="line">    &quot;hits&quot;: [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;BrimyW0B5sayAd6P9LGl&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;CbimyW0B5sayAd6P-LHO&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;D7imyW0B5sayAd6P_LH0&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;ELimyW0B5sayAd6P_bGM&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;BbimyW0B5sayAd6P57Hs&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;B7imyW0B5sayAd6P9rG3&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;EbimyW0B5sayAd6P_rEo&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;1&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;CLimyW0B5sayAd6P97Hz&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;CrimyW0B5sayAd6P-bGO&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;sort&quot;: [</span><br><span class="line">          32,</span><br><span class="line">          1</span><br><span class="line">        ]</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="6-4-实践中的基础模块"><a href="#6-4-实践中的基础模块" class="headerlink" title="6.4 实践中的基础模块"></a>6.4 实践中的基础模块</h2><p>结合上面的几个点，总结出了下面一个查询内容</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;from&quot;: 0,</span><br><span class="line">  &quot;size&quot;: 2,</span><br><span class="line">  &quot;_source&quot;: [&quot;*_name&quot;, &quot;age&quot;],</span><br><span class="line">  &quot;sort&quot;: [</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;age&quot;:&quot;desc&quot;  </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="6-4-1-理解回复的内容"><a href="#6-4-1-理解回复的内容" class="headerlink" title="6.4.1 理解回复的内容"></a>6.4.1 理解回复的内容</h3><p>注意点： 如果没有存储文档的_source 和 fields, 无法从es 获取数值</p>
<h2 id="6-5-查询和过滤器DSL-（重点）"><a href="#6-5-查询和过滤器DSL-（重点）" class="headerlink" title="6.5 查询和过滤器DSL （重点）"></a>6.5 查询和过滤器DSL （重点）</h2><h3 id="6-5-1-match-查询和term过滤器"><a href="#6-5-1-match-查询和term过滤器" class="headerlink" title="6.5.1 match 查询和term过滤器"></a>6.5.1 match 查询和term过滤器</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &quot;Jane&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>注意：此处 <strong>jane</strong> 是否大写对于查询结果没有影响</p>
<h4 id="过滤器和查询器有什么不同："><a href="#过滤器和查询器有什么不同：" class="headerlink" title="过滤器和查询器有什么不同："></a>过滤器和查询器有什么不同：</h4><p>查询器：为特定的词条计算得分</p>
<p>过滤器：</p>
<ol>
<li>“文档是否匹配这个查询” 返回简单的是或者否</li>
<li>限制了需要计算得分的文档数量</li>
<li>根据过滤器的种类，可以再“位集合”中缓存结果</li>
<li>允许手动指定一个过滤器是否应该被缓存</li>
</ol>
<blockquote>
<p>基于如上原因，过滤器会比查询器要快上很多，并且查询结果可以被缓存</p>
</blockquote>
<h4 id="es6以下-以及旧版本使用的方式"><a href="#es6以下-以及旧版本使用的方式" class="headerlink" title="es6以下 以及旧版本使用的方式"></a>es6以下 以及旧版本使用的方式</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;query&quot;:&#123;</span><br><span class="line">        &quot;filtedred&quot;:&#123; -- 表示指定一个附上过滤器的查询</span><br><span class="line">            &quot;query&quot;:&#123; -- 指定查询器</span><br><span class="line">                &quot;match&quot;: &quot;xxx&quot;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;filter&quot;:&#123; -- 指定过滤器</span><br><span class="line">                &quot;term&quot;:&#123;</span><br><span class="line">                    ....</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>仅做了解即可，新版更为简单易用</p>
<h4 id="这里需要注意下面使用的是es6以及以上版本"><a href="#这里需要注意下面使用的是es6以及以上版本" class="headerlink" title="这里需要注意下面使用的是es6以及以上版本"></a>这里需要注意下面使用的是es6以及以上版本</h4><blockquote>
<p>es6 之后使用</p>
<p>bool:{</p>
<p>must 表示匹配操作</p>
<p>可以执行match 操作</p>
<p>filter:</p>
<p>对于结果进行过滤,</p>
<p>这要比在全部搜索中去匹配要快的多</p>
<p>}</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  </span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;match&quot;: &#123;</span><br><span class="line">            &quot;about&quot;: &quot;hide&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ], </span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;wang&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;took&quot;: 16,</span><br><span class="line">  &quot;timed_out&quot;: false,</span><br><span class="line">  &quot;_shards&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 5,</span><br><span class="line">    &quot;successful&quot;: 5,</span><br><span class="line">    &quot;skipped&quot;: 0,</span><br><span class="line">    &quot;failed&quot;: 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 1,</span><br><span class="line">    &quot;max_score&quot;: 1.2039728,</span><br><span class="line">    &quot;hits&quot;: [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;E7joyW0B5sayAd6PEbFA&quot;,</span><br><span class="line">        &quot;_score&quot;: 1.2039728,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;wang&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;laji&quot;,</span><br><span class="line">          &quot;age&quot;: 333,</span><br><span class="line">          &quot;about&quot;: &quot;I hide to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;basket&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="6-6-常用的基础查询和过滤器"><a href="#6-6-常用的基础查询和过滤器" class="headerlink" title="6.6 常用的基础查询和过滤器"></a>6.6 常用的基础查询和过滤器</h2><h3 id="6-6-1-match-all-的使用场景"><a href="#6-6-1-match-all-的使用场景" class="headerlink" title="6.6.1 match_all 的使用场景"></a>6.6.1 match_all 的使用场景</h3><ol>
<li>希望使用过滤器的时候</li>
<li>希望返回被搜索的索引和类型的全部文档</li>
</ol>
<h3 id="6-6-2-query-string-查询"><a href="#6-6-2-query-string-查询" class="headerlink" title="6.6.2 query_string 查询"></a>6.6.2 query_string 查询</h3><blockquote>
<p>注意事项:</p>
<p>AND 必须大写， 即查询条件的连接符， 否则系统会当做查询字符串的内容进行识别</p>
<p>查询条件连接符两边必须加上一个空格区分</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_search?q&#x3D;wang</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      &quot;default_field&quot;: &quot;first_name&quot;,</span><br><span class="line">      &quot;query&quot;: &quot;first_name:wang AND age:333&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="使用query-string-进行复杂的查询"><a href="#使用query-string-进行复杂的查询" class="headerlink" title="使用query_string 进行复杂的查询"></a>使用query_string 进行复杂的查询</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123; tags:search OR tags:lucene&#125; AND create_on:[1999-01-01 TO 2011-01-01]</span><br></pre></td></tr></table></figure>

<p>这是一个示例查询</p>
<p>下面为个人实验案例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      &quot;default_field&quot;: &quot;first_name&quot;,</span><br><span class="line">      &quot;query&quot;: &quot;first_name:wang OR first_name:jane AND age:[0 TO 999]&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>由于query_string 过于强大：建议的替代方案为使用 term, terms, match 或者 multi_match</p>
<p>允许你在一个或者多个文档搜索</p>
<p>或者使用 simple_query_string</p>
<p>使用 +、-、AND 和 OR 更容易使用的查询语法</p>
</blockquote>
<h3 id="6-6-3-term-查询和-term过滤器"><a href="#6-6-3-term-查询和-term过滤器" class="headerlink" title="6.6.3 term 查询和 term过滤器"></a>6.6.3 term 查询和 term过滤器</h3><ol>
<li>最简单的几个可执行查询之一</li>
<li>指定需要搜索的词条和字段</li>
<li>了解term(词条)查询</li>
</ol>
<blockquote>
<p>注意：被搜索的词条没有经过分析，文档的词条要经过精确匹配才能作为结果返回</p>
</blockquote>
<h4 id="使用term-过滤器的得分，和term查询器的得分对比"><a href="#使用term-过滤器的得分，和term查询器的得分对比" class="headerlink" title="使用term 过滤器的得分，和term查询器的得分对比"></a>使用term 过滤器的得分，和term查询器的得分对比</h4><p>使用过滤器</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;_id&quot;: 1</span><br><span class="line">        &#125;        </span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;took&quot;: 10,</span><br><span class="line">  &quot;timed_out&quot;: false,</span><br><span class="line">  &quot;_shards&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 5,</span><br><span class="line">    &quot;successful&quot;: 5,</span><br><span class="line">    &quot;skipped&quot;: 0,</span><br><span class="line">    &quot;failed&quot;: 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 1,</span><br><span class="line">    &quot;max_score&quot;: 0,</span><br><span class="line">    &quot;hits&quot;: [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;1&quot;,</span><br><span class="line">        &quot;_score&quot;: 0,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;Jane&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;Smith&quot;,</span><br><span class="line">          &quot;age&quot;: 32,</span><br><span class="line">          &quot;about&quot;: &quot;I like to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;music&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>使用查询器</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;term&quot;: &#123;</span><br><span class="line">            &quot;first_name&quot;: &quot;wang&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;took&quot;: 9,</span><br><span class="line">  &quot;timed_out&quot;: false,</span><br><span class="line">  &quot;_shards&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 5,</span><br><span class="line">    &quot;successful&quot;: 5,</span><br><span class="line">    &quot;skipped&quot;: 0,</span><br><span class="line">    &quot;failed&quot;: 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 1,</span><br><span class="line">    &quot;max_score&quot;: 1.2039728,</span><br><span class="line">    &quot;hits&quot;: [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;E7joyW0B5sayAd6PEbFA&quot;,</span><br><span class="line">        &quot;_score&quot;: 1.2039728,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;wang&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;laji&quot;,</span><br><span class="line">          &quot;age&quot;: 333,</span><br><span class="line">          &quot;about&quot;: &quot;I hide to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;basket&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="6-6-4-terms-查询"><a href="#6-6-4-terms-查询" class="headerlink" title="6.6.4 terms 查询"></a>6.6.4 terms 查询</h3><p>使用多词条查询搜索多个词条</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;terms&quot;: &#123;</span><br><span class="line">      &quot;about&quot;: [</span><br><span class="line">        &quot;i&quot;,</span><br><span class="line">        &quot;hide&quot;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>可以强制规定每篇文档中匹配词条的最小数量</p>
<p>mininum_should_match 参数</p>
<blockquote>
<p>注意：在新的版本当中只有过滤器才能制定该参数</p>
</blockquote>
<h3 id="6-5-5-match查询和-term过滤器"><a href="#6-5-5-match查询和-term过滤器" class="headerlink" title="6.5.5 match查询和 term过滤器"></a>6.5.5 match查询和 term过滤器</h3><p>match查询可以有多重行为方式，最常见就是<strong>布尔(bool)\</strong>和*<em>词组(phrase)*</em></p>
<h4 id="布尔查询行为"><a href="#布尔查询行为" class="headerlink" title="布尔查询行为"></a>布尔查询行为</h4><p>默认情况match查询使用布尔行为和OR操作符号， 如 “es den” 默认是”es OR den”</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;Jane wang&quot;,</span><br><span class="line">        &quot;operator&quot;: &quot;or&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>match 查询的第二个重要行为是作为phrase 查询</strong></p>
<h4 id="词组（phrase-）查询的方式"><a href="#词组（phrase-）查询的方式" class="headerlink" title="词组（phrase ）查询的方式"></a>词组（phrase ）查询的方式</h4><blockquote>
<p>在6.x已经不支持在math里面使用type， 可以修改为以下语法：</p>
</blockquote>
<p>可以设置slop 用来实现自动提示中的跨单词匹配的功能</p>
<h5 id="es5版本以及以下的语法："><a href="#es5版本以及以下的语法：" class="headerlink" title="es5版本以及以下的语法："></a>es5版本以及以下的语法：</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;type&quot;: &quot;phrase&quot;,</span><br><span class="line">        &quot;query&quot;: &quot;hide&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>会出现如下报错</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;error&quot;: &#123;</span><br><span class="line">    &quot;root_cause&quot;: [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;type&quot;: &quot;parsing_exception&quot;,</span><br><span class="line">        &quot;reason&quot;: &quot;[match] query does not support [type]&quot;,</span><br><span class="line">        &quot;line&quot;: 5,</span><br><span class="line">        &quot;col&quot;: 17</span><br><span class="line">      &#125;</span><br><span class="line">    ],</span><br><span class="line">    &quot;type&quot;: &quot;parsing_exception&quot;,</span><br><span class="line">    &quot;reason&quot;: &quot;[match] query does not support [type]&quot;,</span><br><span class="line">    &quot;line&quot;: 5,</span><br><span class="line">    &quot;col&quot;: 17</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;status&quot;: 400</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h5 id="es6以及以上要使用以下语法"><a href="#es6以及以上要使用以下语法" class="headerlink" title="es6以及以上要使用以下语法"></a>es6以及以上要使用以下语法</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_phrase&quot;: &#123;</span><br><span class="line">      &quot;about&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;to rock&quot;,</span><br><span class="line">        &quot;slop&quot;:1</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>注意：slop 为0 代表中间不进行跳行匹配,默认为0</p>
<h3 id="6-5-6-phrase-prefix-查询"><a href="#6-5-6-phrase-prefix-查询" class="headerlink" title="6.5.6 phrase_prefix 查询"></a>6.5.6 phrase_prefix 查询</h3><p>依据词组的最后一个词条进行前缀匹配</p>
<p>对于搜索框自动完成来说，是一个十分重要的功能</p>
<blockquote>
<p>注意：这种方式最好设置 max_expansions 设置最大的前缀扩展数量</p>
</blockquote>
<h4 id="es5-x-版本以及以下的语法："><a href="#es5-x-版本以及以下的语法：" class="headerlink" title="es5.x 版本以及以下的语法："></a>es5.x 版本以及以下的语法：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;type&quot;: &quot;phrase_prefix&quot;,</span><br><span class="line">        &quot;query&quot;: &quot;hide&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="es6-x-需要改成如下写法"><a href="#es6-x-需要改成如下写法" class="headerlink" title="es6.x 需要改成如下写法"></a>es6.x 需要改成如下写法</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_phrase_prefix&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;wa&quot;,</span><br><span class="line">        &quot;max_expansions&quot;: 5</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;took&quot;: 24,</span><br><span class="line">  &quot;timed_out&quot;: false,</span><br><span class="line">  &quot;_shards&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 5,</span><br><span class="line">    &quot;successful&quot;: 5,</span><br><span class="line">    &quot;skipped&quot;: 0,</span><br><span class="line">    &quot;failed&quot;: 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 1,</span><br><span class="line">    &quot;max_score&quot;: 1.2039728,</span><br><span class="line">    &quot;hits&quot;: [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;lib&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;user&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;E7joyW0B5sayAd6PEbFA&quot;,</span><br><span class="line">        &quot;_score&quot;: 1.2039728,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;wang&quot;,</span><br><span class="line">          &quot;last_name&quot;: &quot;laji&quot;,</span><br><span class="line">          &quot;age&quot;: 333,</span><br><span class="line">          &quot;about&quot;: &quot;I hide to collect rock albums&quot;,</span><br><span class="line">          &quot;interests&quot;: [</span><br><span class="line">            &quot;basket&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>bool查询和phrase 查询 对于接受用户输入是很好的选择</p>
<h4 id="使用multi-match-匹配多个字段"><a href="#使用multi-match-匹配多个字段" class="headerlink" title="使用multi_match 匹配多个字段"></a>使用multi_match 匹配多个字段</h4><p>和match 多个字段有细微的区别：</p>
<p>允许搜索多个字段中的值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;multi_match&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;wang smith&quot;,</span><br><span class="line">        &quot;fields&quot;: [&quot;first_name&quot;, &quot;last_name&quot;]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>multi_match 也可以转化为 phrase(词组) 查询 或者 phrase_prefix 查询</strong></p>
<p>match 查询是核心的查询类型</p>
<h2 id="6-7-组合查询和复合查询"><a href="#6-7-组合查询和复合查询" class="headerlink" title="6.7 组合查询和复合查询"></a>6.7 组合查询和复合查询</h2><h3 id="6-7-1-bool查询"><a href="#6-7-1-bool查询" class="headerlink" title="6.7.1 bool查询"></a>6.7.1 bool查询</h3><p>有以下类别：</p>
<ol>
<li>必须(must)</li>
<li>应该(should)</li>
<li>不能(must_not)</li>
</ol>
<ul>
<li>如果指定了bool查询的部分是must匹配， 只有匹配上结果才能返回</li>
<li>如果指定了bool查询的部分是should匹配， 只有匹配上<strong>指定数量子句</strong>的文档才会被返回</li>
<li>如果没有must匹配，至少要匹配一个should子句才能返回</li>
<li>must_not 子句会使得文档被移除结果集合</li>
</ul>
<p>下面使用一个综合的例子进行试验</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;match_phrase&quot;:  &#123;</span><br><span class="line">            &quot;about&quot;: &#123;</span><br><span class="line">              &quot;query&quot;: &quot;i to&quot;,</span><br><span class="line">              &quot;slop&quot;: 1</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;should&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;term&quot;: &#123;</span><br><span class="line">            &quot;first_name&quot;: &#123;</span><br><span class="line">              &quot;value&quot;: &quot;wang&quot;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;must_not&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;query_string&quot;: &#123;</span><br><span class="line">            &quot;default_field&quot;: &quot;age&quot;,</span><br><span class="line">            &quot;query&quot;: &quot;first_name:jane&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;minimum_should_match&quot;: 1 --指定至少shold子句匹配数，满足才能返回结果</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="6-7-2-bool-的过滤器"><a href="#6-7-2-bool-的过滤器" class="headerlink" title="6.7.2 bool 的过滤器"></a>6.7.2 bool 的过滤器</h3><p>ES6 经过调整，已经将bool的查询器移除，只做过滤功能</p>
<p>es存在如下写法:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">query</span><br><span class="line">	filtered:</span><br><span class="line">        filter:</span><br><span class="line">            bool:</span><br><span class="line">                must:</span><br><span class="line">                should:</span><br><span class="line">                must_not:</span><br></pre></td></tr></table></figure>

<blockquote>
<p>小贴士：</p>
<p>mininum_should_match 默认有一些隐藏特性</p>
<p>如果指定了must 子句</p>
<p><strong>默认值就会变为0</strong>,</p>
<p>如果没有Must子句</p>
<p><strong>默认就是1</strong></p>
</blockquote>
<h2 id="6-8-超越match-和-过滤器的查询"><a href="#6-8-超越match-和-过滤器的查询" class="headerlink" title="6.8 超越match 和 过滤器的查询"></a>6.8 超越match 和 过滤器的查询</h2><h3 id="6-8-1-range-查询和过滤器"><a href="#6-8-1-range-查询和过滤器" class="headerlink" title="6.8.1 range 查询和过滤器"></a>6.8.1 range 查询和过滤器</h3><h4 id="模拟数据"><a href="#模拟数据" class="headerlink" title="模拟数据"></a>模拟数据</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;test&#x2F;5</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;: &quot;CHENLONG_looo&quot;,</span><br><span class="line">  &quot;age&quot;: 66,</span><br><span class="line">  &quot;birthday&quot;: &quot;2016-10-10&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;myindex&#x2F;test&#x2F;5</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;: &quot;CHENLONG&quot;,</span><br><span class="line">  &quot;age&quot;: 15,</span><br><span class="line">  &quot;birthday&quot;: &quot;2011-02-14&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;myindex&#x2F;test&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">  &quot;age&quot;: 5,</span><br><span class="line">  &quot;birthday&quot;: &quot;2019-05-04&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="现在需要查找出-11-年到-16年的数据"><a href="#现在需要查找出-11-年到-16年的数据" class="headerlink" title="现在需要查找出 11 年到 16年的数据"></a>现在需要查找出 11 年到 16年的数据</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;range&quot;: &#123;</span><br><span class="line">      &quot;birthday&quot;: &#123;</span><br><span class="line">        &quot;gte&quot;: &quot;2011-06-11&quot;,</span><br><span class="line">        &quot;lte&quot;: &quot;2020-01-01&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;took&quot;: 29,</span><br><span class="line">  &quot;timed_out&quot;: false,</span><br><span class="line">  &quot;_shards&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 5,</span><br><span class="line">    &quot;successful&quot;: 5,</span><br><span class="line">    &quot;skipped&quot;: 0,</span><br><span class="line">    &quot;failed&quot;: 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 2,</span><br><span class="line">    &quot;max_score&quot;: 1,</span><br><span class="line">    &quot;hits&quot;: [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;myindex&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;test&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;5&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;CHENLONG_looo&quot;,</span><br><span class="line">          &quot;age&quot;: 66,</span><br><span class="line">          &quot;birthday&quot;: &quot;2016-10-10&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_index&quot;: &quot;myindex&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;test&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;1&quot;,</span><br><span class="line">        &quot;_score&quot;: 1,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">          &quot;age&quot;: 55,</span><br><span class="line">          &quot;birthday&quot;: &quot;2019-05-04&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>range支持字符串的范围匹配，如 “li” 到 “e” 之间的分组</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;range&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;gte&quot;: &quot;li&quot;,</span><br><span class="line">        &quot;lte&quot;: &quot;o&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>range 应该用于过滤而不是查询</p>
<h3 id="6-8-2-prefix-查询和过滤器"><a href="#6-8-2-prefix-查询和过滤器" class="headerlink" title="6.8.2 prefix 查询和过滤器"></a>6.8.2 prefix 查询和过滤器</h3><p>prefix 查询和过滤器允许给定的前缀来搜索词条,<strong>这里的前缀在搜索之前没有经过分析</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;prefix&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;value&quot;: &quot;li&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>匹配 li 开头的词条</p>
<h4 id="在过滤器当中使用"><a href="#在过滤器当中使用" class="headerlink" title="在过滤器当中使用"></a>在过滤器当中使用</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;prefix&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;li&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>注意过滤器会跳过得分计算，所以效率要高于查询</p>
<blockquote>
<p>注意： 由于搜索前缀不会被分析，所以大小写是进行区分的</p>
<p>原因：es分析文档和查询的方式引起的</p>
</blockquote>
<h3 id="6-8-3-wildcard-查询"><a href="#6-8-3-wildcard-查询" class="headerlink" title="6.8.3 wildcard 查询"></a>6.8.3 wildcard 查询</h3><p>正则表达式的搜索方式：</p>
<p>更像是 shell 通配符 globbing 的工作方式：</p>
<p>ls *foo?ar</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;wildcard&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;value&quot;: &quot;lix?ao*&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>要注意的是：这种正则匹配并不像match 那样轻量级</p>
<p>如果需要用于系统，要进行数据分析以及测试</p>
<h2 id="6-9-使用过滤器查询字段的存在性"><a href="#6-9-使用过滤器查询字段的存在性" class="headerlink" title="6.9 使用过滤器查询字段的存在性"></a>6.9 使用过滤器查询字段的存在性</h2><h3 id="6-9-1-exists-过滤器"><a href="#6-9-1-exists-过滤器" class="headerlink" title="6.9.1 exists 过滤器"></a>6.9.1 exists 过滤器</h3><p>只查找那些特定字段有值的文档</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;exists&quot;: &#123;</span><br><span class="line">          &quot;field&quot;: &quot;name&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="6-9-2-missing-过滤器（6-x以上版本已经删除）"><a href="#6-9-2-missing-过滤器（6-x以上版本已经删除）" class="headerlink" title="6.9.2 missing 过滤器（6.x以上版本已经删除）"></a>6.9.2 missing 过滤器（6.x以上版本已经删除）</h3><p>可以搜索字段里没有的值，或者映射的时候默认指定的默认值的文档（映射里的 null_value）</p>
<h4 id="作为测试-先插入一条增加一个字段的数据"><a href="#作为测试-先插入一条增加一个字段的数据" class="headerlink" title="作为测试,先插入一条增加一个字段的数据"></a>作为测试,先插入一条增加一个字段的数据</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;test&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">  &quot;age&quot;: 5,</span><br><span class="line">  &quot;birthday&quot;: &quot;2019-05-04&quot;,</span><br><span class="line">  &quot;test_field&quot;: &quot;zzzzzz&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="接下来，查找字段里没有的值-这样写是错误的，没有正确写法（6-x）"><a href="#接下来，查找字段里没有的值-这样写是错误的，没有正确写法（6-x）" class="headerlink" title="接下来，查找字段里没有的值,这样写是错误的，没有正确写法（6.x）"></a>接下来，查找字段里没有的值,这样写是错误的，没有正确写法（6.x）</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;missing&quot;: &#123;</span><br><span class="line">          &quot;field&quot;: &quot;test_field&quot;,</span><br><span class="line">          &quot;existence&quot;: true,</span><br><span class="line">          &quot;null_value&quot;: true</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="6-9-3-将任何查询转为过滤器"><a href="#6-9-3-将任何查询转为过滤器" class="headerlink" title="6.9.3 将任何查询转为过滤器"></a>6.9.3 将任何查询转为过滤器</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;query_string&quot;: &#123;</span><br><span class="line">            &quot;default_field&quot;: &quot;name&quot;,</span><br><span class="line">            &quot;query&quot;: &quot;che*&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="缓存过滤器"><a href="#缓存过滤器" class="headerlink" title="缓存过滤器"></a>缓存过滤器</h4><p>加入 _cache: true 配置</p>
<h3 id="6-9-4-为任务选择最好的查询"><a href="#6-9-4-为任务选择最好的查询" class="headerlink" title="6.9.4 为任务选择最好的查询"></a>6.9.4 为任务选择最好的查询</h3><h1 id="7-分析数据"><a href="#7-分析数据" class="headerlink" title="7. 分析数据"></a>7. 分析数据</h1><h2 id="7-1-什么是分析数据"><a href="#7-1-什么是分析数据" class="headerlink" title="7.1 什么是分析数据"></a>7.1 什么是分析数据</h2><ol>
<li>字符过滤：使用字符过滤器转变字符</li>
<li>文本切分为分词：将文本切分为单个或者多个分词</li>
<li>分词过滤：使用分词过滤器转变为每个分词</li>
<li>分词索引：将这些分词存储到索引中</li>
</ol>
<h3 id="7-1-1-字符过滤"><a href="#7-1-1-字符过滤" class="headerlink" title="7.1.1 字符过滤"></a>7.1.1 字符过滤</h3><p>主要是排除一些HTML标签以及特殊符号转为可以搜索是是别的词条</p>
<h3 id="7-1-2-切分为分词"><a href="#7-1-2-切分为分词" class="headerlink" title="7.1.2 切分为分词"></a>7.1.2 切分为分词</h3><p>标准分词器：根据空格，换行，破折号进行划分单词</p>
<h3 id="7-1-3-分词过滤器"><a href="#7-1-3-分词过滤器" class="headerlink" title="7.1.3 分词过滤器"></a>7.1.3 分词过滤器</h3><p>最有用和最常用的是<strong>小写分词过滤器</strong>（外国）</p>
<p>中国建议使用 ik 中文分词器</p>
<p>书本的分词过滤为下：</p>
<ol>
<li>分词转小写</li>
<li>删除”停用词”</li>
<li>同义词添加</li>
</ol>
<h3 id="7-1-4-分词索引"><a href="#7-1-4-分词索引" class="headerlink" title="7.1.4 分词索引"></a>7.1.4 分词索引</h3><p>经过分词过滤器过滤之后，将发送到Lucene进行文档索引。最终组成倒排索引</p>
<p>所有不同部分，组成一个分析器</p>
<blockquote>
<p>搜索时候的分析：</p>
<p>如果搜索没有达到预期效果，牢记一条</p>
<p><strong>分析方式和预想的不一致</strong></p>
</blockquote>
<h2 id="7-2-为文档使用分析器"><a href="#7-2-为文档使用分析器" class="headerlink" title="7.2 为文档使用分析器"></a>7.2 为文档使用分析器</h2><p>以下两种方式指定字段使用的分析器</p>
<ul>
<li>创建索引的时候，为特定索引进行设置</li>
<li>es配置文件中，配置全局分析器</li>
</ul>
<h3 id="7-2-1-创建索引的过程中，添加定制分析器"><a href="#7-2-1-创建索引的过程中，添加定制分析器" class="headerlink" title="7.2.1 创建索引的过程中，添加定制分析器"></a>7.2.1 创建索引的过程中，添加定制分析器</h3><p>参考：</p>
<p><span class="exturl" data-url="aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dzeXcxMjYvYXJ0aWNsZS9kZXRhaWxzLzcxMDgwMjg1" title="https://blog.csdn.net/wsyw126/article/details/71080285">https://blog.csdn.net/wsyw126/article/details/71080285<i class="fa fa-external-link"></i></span></p>
<h4 id="旧版本的使用方式"><a href="#旧版本的使用方式" class="headerlink" title="旧版本的使用方式"></a>旧版本的使用方式</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;mymyindex&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;:&#123;</span><br><span class="line">    &quot;number_of_shards&quot;: 2,</span><br><span class="line">    &quot;number_of_replicas&quot;: 1,</span><br><span class="line">    &quot;index&quot;: &#123;</span><br><span class="line">      &quot;analysis&quot;: &#123;</span><br><span class="line">        &quot;myCustomAnalyzer&quot;:&#123;</span><br><span class="line">          &quot;type&quot;: &quot;custom&quot;,</span><br><span class="line">          &quot;tokenizer&quot;: &quot;myCustomTokenizer&quot;,</span><br><span class="line">          &quot;filter&quot;: [&quot;myCustomFilter1&quot;, &quot;myCustomFilter2&quot;],</span><br><span class="line">          &quot;char_filter&quot;: [&quot;myCustomCharFilter&quot;]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;tokenizer&quot;: &#123;</span><br><span class="line">      &quot;myCustomTokenizer&quot;: &#123;</span><br><span class="line">        &quot;type&quot;: &quot;letter&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;filter&quot;: &#123;</span><br><span class="line">      &quot;myCustomFilter1&quot;: &#123;</span><br><span class="line">        &quot;type&quot;: &quot;lowercase&quot;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;myCustomFilter2&quot;:&#123;</span><br><span class="line">        &quot;type&quot;: &quot;kstem&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    &quot;char_filter&quot;:&#123;</span><br><span class="line">      &quot;myCustomCharFilter&quot;:&#123;</span><br><span class="line">        &quot;type&quot;: &quot;mapping&quot;,</span><br><span class="line">        &quot;mappings&quot;: [&quot;ph&#x3D;&gt;f&quot;, &quot;u&#x3D;&gt;you&quot;]</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;mappings&quot;:&#123;</span><br><span class="line">    </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="网上的案例："><a href="#网上的案例：" class="headerlink" title="网上的案例："></a>网上的案例：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;my_index</span><br><span class="line">&#123;</span><br><span class="line">    &quot;settings&quot;: &#123;</span><br><span class="line">        &quot;analysis&quot;: &#123;</span><br><span class="line">            &quot;char_filter&quot;: &#123;</span><br><span class="line">                &quot;&amp;_to_and&quot;: &#123;</span><br><span class="line">                    &quot;type&quot;:       &quot;mapping&quot;,</span><br><span class="line">                    &quot;mappings&quot;: [ &quot;&amp; &#x3D;&gt; and &quot;]</span><br><span class="line">            &#125;&#125;,</span><br><span class="line">            &quot;filter&quot;: &#123;</span><br><span class="line">                &quot;my_stopwords&quot;: &#123;</span><br><span class="line">                    &quot;type&quot;:       &quot;stop&quot;,</span><br><span class="line">                    &quot;stopwords&quot;: [ &quot;the&quot;, &quot;a&quot; ]</span><br><span class="line">            &#125;&#125;,</span><br><span class="line">            &quot;analyzer&quot;: &#123;</span><br><span class="line">                &quot;my_analyzer&quot;: &#123;</span><br><span class="line">                    &quot;type&quot;:         &quot;custom&quot;,</span><br><span class="line">                    &quot;char_filter&quot;:  [ &quot;html_strip&quot;, &quot;&amp;_to_and&quot; ],</span><br><span class="line">                    &quot;tokenizer&quot;:    &quot;standard&quot;,</span><br><span class="line">                    &quot;filter&quot;:       [ &quot;lowercase&quot;, &quot;my_stopwords&quot; ]</span><br><span class="line">            &#125;&#125;</span><br><span class="line">        &#125; </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>上面的网上案例使用 _settings 查看结果是这样的</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;my_index&quot;: &#123;</span><br><span class="line">    &quot;settings&quot;: &#123;</span><br><span class="line">      &quot;index&quot;: &#123;</span><br><span class="line">        &quot;number_of_shards&quot;: &quot;5&quot;,</span><br><span class="line">        &quot;provided_name&quot;: &quot;my_index&quot;,</span><br><span class="line">        &quot;creation_date&quot;: &quot;1571079347660&quot;,</span><br><span class="line">        &quot;analysis&quot;: &#123;</span><br><span class="line">          &quot;filter&quot;: &#123;</span><br><span class="line">            &quot;my_stopwords&quot;: &#123;</span><br><span class="line">              &quot;type&quot;: &quot;stop&quot;,</span><br><span class="line">              &quot;stopwords&quot;: [</span><br><span class="line">                &quot;the&quot;,</span><br><span class="line">                &quot;a&quot;</span><br><span class="line">              ]</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;analyzer&quot;: &#123;</span><br><span class="line">            &quot;my_analyzer&quot;: &#123;</span><br><span class="line">              &quot;filter&quot;: [</span><br><span class="line">                &quot;lowercase&quot;,</span><br><span class="line">                &quot;my_stopwords&quot;</span><br><span class="line">              ],</span><br><span class="line">              &quot;char_filter&quot;: [</span><br><span class="line">                &quot;html_strip&quot;,</span><br><span class="line">                &quot;&amp;_to_and&quot;</span><br><span class="line">              ],</span><br><span class="line">              &quot;type&quot;: &quot;custom&quot;,</span><br><span class="line">              &quot;tokenizer&quot;: &quot;standard&quot;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;,</span><br><span class="line">          &quot;char_filter&quot;: &#123;</span><br><span class="line">            &quot;&amp;_to_and&quot;: &#123;</span><br><span class="line">              &quot;type&quot;: &quot;mapping&quot;,</span><br><span class="line">              &quot;mappings&quot;: [</span><br><span class="line">                &quot;&amp; &#x3D;&gt; and &quot;</span><br><span class="line">              ]</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;number_of_replicas&quot;: &quot;1&quot;,</span><br><span class="line">        &quot;uuid&quot;: &quot;gYyxkcIRRWqLtWhjMd24CQ&quot;,</span><br><span class="line">        &quot;version&quot;: &#123;</span><br><span class="line">          &quot;created&quot;: &quot;6020499&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="将书上的案例改为6-x支持的形式，格式如下"><a href="#将书上的案例改为6-x支持的形式，格式如下" class="headerlink" title="将书上的案例改为6.x支持的形式，格式如下:"></a>将书上的案例改为6.x支持的形式，格式如下:</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;mymyindex&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">	&quot;settings&quot;: &#123;</span><br><span class="line">		&quot;number_of_shards&quot;: 2,</span><br><span class="line">		&quot;number_of_replicas&quot;: 1,</span><br><span class="line">		&quot;analysis&quot;: &#123;</span><br><span class="line">			&quot;myCustomAnalyzer&quot;: &#123;</span><br><span class="line">				&quot;type&quot;: &quot;custom&quot;,</span><br><span class="line">				&quot;tokenizer&quot;: &quot;myCustomTokenizer&quot;,</span><br><span class="line">				&quot;filter&quot;: [&quot;myCustomFilter1&quot;, &quot;myCustomFilter2&quot;],</span><br><span class="line">				&quot;char_filter&quot;: [&quot;myCustomCharFilter&quot;]</span><br><span class="line">			&#125;,</span><br><span class="line">			&quot;tokenizer&quot;: &#123;</span><br><span class="line">				&quot;myCustomTokenizer&quot;: &#123;</span><br><span class="line">					&quot;type&quot;: &quot;letter&quot;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;,</span><br><span class="line">			&quot;filter&quot;: &#123;</span><br><span class="line">				&quot;myCustomFilter1&quot;: &#123;</span><br><span class="line">					&quot;type&quot;: &quot;lowercase&quot;</span><br><span class="line">				&#125;,</span><br><span class="line">				&quot;myCustomFilter2&quot;: &#123;</span><br><span class="line">					&quot;type&quot;: &quot;kstem&quot;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;,</span><br><span class="line">			&quot;char_filter&quot;: &#123;</span><br><span class="line">				&quot;myCustomCharFilter&quot;: &#123;</span><br><span class="line">					&quot;type&quot;: &quot;mapping&quot;,</span><br><span class="line">					&quot;mappings&quot;: [&quot;ph&#x3D;&gt;f&quot;, &quot;u&#x3D;&gt;you&quot;]</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">	&#125;,</span><br><span class="line">	&quot;mappings&quot;: &#123;</span><br><span class="line"></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="7-2-2-使用elasticsearch-yml-的配置文件进行配置"><a href="#7-2-2-使用elasticsearch-yml-的配置文件进行配置" class="headerlink" title="7.2.2 使用elasticsearch.yml 的配置文件进行配置"></a>7.2.2 使用elasticsearch.yml 的配置文件进行配置</h3><p>目前没有理解如何配置，需要到官方文档去摸索</p>
<h3 id="7-2-3-在映射中指定某个字段的分析器"><a href="#7-2-3-在映射中指定某个字段的分析器" class="headerlink" title="7.2.3 在映射中指定某个字段的分析器"></a>7.2.3 在映射中指定某个字段的分析器</h3><h4 id="书本的方式已经不适用于6-x版本了，根据官方文档的内容要进行如下定义"><a href="#书本的方式已经不适用于6-x版本了，根据官方文档的内容要进行如下定义" class="headerlink" title="书本的方式已经不适用于6.x版本了，根据官方文档的内容要进行如下定义"></a>书本的方式已经不适用于6.x版本了，根据官方文档的内容要进行如下定义</h4><p>注意下文有使用到该索引</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;mymyindex</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;: &#123;</span><br><span class="line">    &quot;analysis&quot;: &#123;</span><br><span class="line">      &quot;analyzer&quot;: &#123;</span><br><span class="line">        &quot;std_folded&quot;: &#123; </span><br><span class="line">          &quot;type&quot;: &quot;custom&quot;,</span><br><span class="line">          &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">          &quot;filter&quot;: [</span><br><span class="line">            &quot;lowercase&quot;,</span><br><span class="line">            &quot;asciifolding&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;mappings&quot;: &#123;</span><br><span class="line">    &quot;_doc&quot;: &#123;</span><br><span class="line">      &quot;properties&quot;: &#123;</span><br><span class="line">        &quot;my_text&quot;: &#123;</span><br><span class="line">          &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">          &quot;analyzer&quot;: &quot;std_folded&quot; </span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="7-3-使用API来分析文本"><a href="#7-3-使用API来分析文本" class="headerlink" title="7.3 使用API来分析文本"></a>7.3 使用API来分析文本</h2><h3 id="7-3-1-使用-analyzer-内置API来进行分析分析器解析步骤"><a href="#7-3-1-使用-analyzer-内置API来进行分析分析器解析步骤" class="headerlink" title="7.3.1 使用_analyzer 内置API来进行分析分析器解析步骤"></a>7.3.1 使用_analyzer 内置API来进行分析分析器解析步骤</h3><p>下面是官方的测试用例：使用的官方内置的 <strong>standard（标准）</strong>分析器</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST &quot;192.168.92.180:9200&#x2F;_analyze?pretty&quot; -H &#39;Content-Type: application&#x2F;json&#39; -d&#39;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;analyzer&quot;: &quot;standard&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog\u0027s bone.&quot;</span><br><span class="line">&#125;</span><br><span class="line">&#39;</span><br></pre></td></tr></table></figure>

<p>结果如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;tokens&quot; : [</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;the&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 0,</span><br><span class="line">      &quot;end_offset&quot; : 3,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 0</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;2&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 4,</span><br><span class="line">      &quot;end_offset&quot; : 5,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;NUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 1</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;quick&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 6,</span><br><span class="line">      &quot;end_offset&quot; : 11,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 2</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;brown&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 12,</span><br><span class="line">      &quot;end_offset&quot; : 17,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 3</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;foxes&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 18,</span><br><span class="line">      &quot;end_offset&quot; : 23,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 4</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;jumped&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 24,</span><br><span class="line">      &quot;end_offset&quot; : 30,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 5</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;over&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 31,</span><br><span class="line">      &quot;end_offset&quot; : 35,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 6</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;the&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 36,</span><br><span class="line">      &quot;end_offset&quot; : 39,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 7</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;lazy&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 40,</span><br><span class="line">      &quot;end_offset&quot; : 44,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 8</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;dog&#39;s&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 45,</span><br><span class="line">      &quot;end_offset&quot; : 50,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 9</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;token&quot; : &quot;bone&quot;,</span><br><span class="line">      &quot;start_offset&quot; : 51,</span><br><span class="line">      &quot;end_offset&quot; : 55,</span><br><span class="line">      &quot;type&quot; : &quot;&lt;ALPHANUM&gt;&quot;,</span><br><span class="line">      &quot;position&quot; : 10</span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>POST my_index/_analyze?analyzer=standard 注意：传参数这样使用时 错误的</p>
<p>需要使用如下方式</p>
<p>POST my_index/_analyze { “analyzer”: “standard”, “text”: “The 2 QUICK Brown-Foxes jumped over the lazy dog’s bone.” }</p>
</blockquote>
<h3 id="7-3-2-分析中指定自定义分析器"><a href="#7-3-2-分析中指定自定义分析器" class="headerlink" title="7.3.2 分析中指定自定义分析器"></a>7.3.2 分析中指定自定义分析器</h3><p>这里在建立索引的时候用到了上面官方改动案例的索引</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;mymyindex&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;analyzer&quot;: &quot;std_folded&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;this is test word I AM LAZY BOY&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="7-3-3-使用组合即时创建分析器"><a href="#7-3-3-使用组合即时创建分析器" class="headerlink" title="7.3.3 使用组合即时创建分析器"></a>7.3.3 使用组合即时创建分析器</h3><h4 id="使用curl方式"><a href="#使用curl方式" class="headerlink" title="使用curl方式"></a>使用curl方式</h4><p>6.x 语法有变，必须放在大括号里面</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST &quot;192.168.92.180:9200&#x2F;_analyze?pretty&quot; -H &#39;Content-Type: application&#x2F;json&#39; -d&#39;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog\u0027s bone.&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;filter&quot;: [&quot;lowercase&quot;, &quot;reverse&quot;],</span><br><span class="line"></span><br><span class="line">&quot;tokenizer&quot;: &quot;whitespace&quot;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">&#39;</span><br></pre></td></tr></table></figure>

<p>此时会发现结果以倒序的方式进行分析</p>
<h4 id="使用kibana方式"><a href="#使用kibana方式" class="headerlink" title="使用kibana方式"></a>使用kibana方式</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;my_index&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;whitespace&quot;, </span><br><span class="line">  &quot;filter&quot;: [</span><br><span class="line">    &quot;reverse&quot;</span><br><span class="line">  ],</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog\u0027s bone.&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>大同小异，如果结果没有反转，可能是解析的过程中有其他干扰因素</p>
<h3 id="7-3-4-使用基于某个字段的映射分析"><a href="#7-3-4-使用基于某个字段的映射分析" class="headerlink" title="7.3.4 使用基于某个字段的映射分析"></a>7.3.4 使用基于某个字段的映射分析</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;mymyindex&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;whitespace&quot;, </span><br><span class="line">  &quot;filter&quot;: [</span><br><span class="line">    &quot;reverse&quot;</span><br><span class="line">  ],</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog\u0027s bone.&quot;,</span><br><span class="line">  &quot;field&quot;: &quot;my_text&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>前提条件是必须是存在索引的字段才能进行映射分析</p>
<h3 id="7-3-5-使用词条向量API来学习索引词条"><a href="#7-3-5-使用词条向量API来学习索引词条" class="headerlink" title="7.3.5 使用词条向量API来学习索引词条"></a>7.3.5 使用词条向量API来学习索引词条</h3><p>使用_termvector 的端点来获取词条的更多信息</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;get-together&#x2F;group&#x2F;3q8nz20BXNiyabSjyH-c&#x2F;_termvectors</span><br></pre></td></tr></table></figure>

<p>虽然可以使用，但是内容已经被官方改动，无法查看词条索引</p>
<h2 id="7-4-分析器-分词器和分词过滤器"><a href="#7-4-分析器-分词器和分词过滤器" class="headerlink" title="7.4 分析器/分词器和分词过滤器"></a>7.4 分析器/分词器和分词过滤器</h2><h3 id="7-4-0-分析器的概览"><a href="#7-4-0-分析器的概览" class="headerlink" title="7.4.0 分析器的概览"></a>7.4.0 分析器的概览</h3><ul>
<li>输入文本</li>
<li>分析器<ul>
<li>字符过滤器</li>
<li>分词器</li>
<li>分词过滤器</li>
</ul>
</li>
<li>输出分词</li>
</ul>
<h3 id="7-4-1-内置分析器"><a href="#7-4-1-内置分析器" class="headerlink" title="7.4.1 内置分析器"></a>7.4.1 内置分析器</h3><p><strong>Standard Analyzer</strong></p>
<p>The <code>standard</code> analyzer divides text into terms on word boundaries, as defined by the Unicode Text Segmentation algorithm. It removes most punctuation, lowercases terms, and supports removing stop words.</p>
<p><strong>Simple Analyzer</strong></p>
<p>The <code>simple</code> analyzer divides text into terms whenever it encounters a character which is not a letter. It lowercases all terms.</p>
<p><strong>Whitespace Analyzer</strong></p>
<p>The <code>whitespace</code> analyzer divides text into terms whenever it encounters any whitespace character. It does not lowercase terms.</p>
<p><strong>Stop Analyzer</strong></p>
<p>The <code>stop</code> analyzer is like the <code>simple</code> analyzer, but also supports removal of stop words.</p>
<p><strong>Keyword Analyzer</strong></p>
<p>The <code>keyword</code> analyzer is a “noop” analyzer that accepts whatever text it is given and outputs the exact same text as a single term.</p>
<p><strong>Pattern Analyzer</strong></p>
<p>The <code>pattern</code> analyzer uses a regular expression to split the text into terms. It supports lower-casing and stop words.</p>
<p><strong>Language Analyzers</strong></p>
<p>Elasticsearch provides many language-specific analyzers like <code>english</code> or <code>french</code>.</p>
<p><strong>Fingerprint Analyzer</strong></p>
<p>The <code>fingerprint</code> analyzer is a specialist analyzer which creates a fingerprint which can be used for duplicate detection.</p>
<p><strong>谷歌翻译之后</strong></p>
<h4 id="标准分析器"><a href="#标准分析器" class="headerlink" title="标准分析器"></a>标准分析器</h4><p>“标准”分析器根据Unicode文本分段算法的定义，将文本划分为单词边界上的各个术语。它删除大多数标点符号，小写术语，并支持删除停用词。</p>
<h4 id="简单分析器"><a href="#简单分析器" class="headerlink" title="简单分析器"></a><strong>简单分析器</strong></h4><p>“简单”分析器在遇到非字母字符时会将文本划分为多个词。它小写所有术语。</p>
<p>只使用小写转化为分词器，注意不适用于亚洲的语言，在欧美这种单词划分的语言适用</p>
<h4 id="空白分析器"><a href="#空白分析器" class="headerlink" title="空白分析器"></a><strong>空白分析器</strong></h4><p>每当遇到任何空白字符时，“空白”分析器都会将文本划分为多个词。它不小写。</p>
<h4 id="停止分析器"><a href="#停止分析器" class="headerlink" title="停止分析器"></a><strong>停止分析器</strong></h4><p>“停止”分析器类似于“简单”分析器，但也支持删除停用词。</p>
<h4 id="关键字分析器"><a href="#关键字分析器" class="headerlink" title="关键字分析器"></a><strong>关键字分析器</strong></h4><p>“关键字”分析器是一个“空”分析器，它接受给出的任何文本，并输出与单个术语完全相同的文本。</p>
<h4 id="模式分析器"><a href="#模式分析器" class="headerlink" title="模式分析器"></a><strong>模式分析器</strong></h4><p>“模式”分析器使用正则表达式将文本分割为多个词。它支持小写字母和停用词。</p>
<h4 id="语言分析器"><a href="#语言分析器" class="headerlink" title="语言分析器"></a><strong>语言分析器</strong></h4><p>Elasticsearch提供了许多特定于语言的分析器，例如“ english”或“ french”。</p>
<h4 id="指纹分析器"><a href="#指纹分析器" class="headerlink" title="指纹分析器"></a><strong>指纹分析器</strong></h4><p>“指纹”分析仪是一种专业分析仪，可创建可用于重复检测的指纹。</p>
<h4 id="雪球分析器"><a href="#雪球分析器" class="headerlink" title="雪球分析器"></a>雪球分析器</h4><p>除了使用标准分词器和标准分词过滤器，也使用了小写分词过滤器以及停用词过滤器，还使用雪球词干进行词干提取</p>
<h3 id="7-4-2-分词器"><a href="#7-4-2-分词器" class="headerlink" title="7.4.2 分词器"></a>7.4.2 分词器</h3><p><strong>Standard Tokenizer</strong></p>
<p>The <code>standard</code> tokenizer divides text into terms on word boundaries, as defined by the Unicode Text Segmentation algorithm. It removes most punctuation symbols. It is the best choice for most languages.</p>
<p><strong>Letter Tokenizer</strong></p>
<p>The <code>letter</code> tokenizer divides text into terms whenever it encounters a character which is not a letter.</p>
<p><strong>Lowercase Tokenizer</strong></p>
<p>The <code>lowercase</code> tokenizer, like the <code>letter</code> tokenizer, divides text into terms whenever it encounters a character which is not a letter, but it also lowercases all terms.</p>
<p><strong>Whitespace Tokenizer</strong></p>
<p>The <code>whitespace</code> tokenizer divides text into terms whenever it encounters any whitespace character.</p>
<p><strong>UAX URL Email Tokenizer</strong></p>
<p>The <code>uax_url_email</code> tokenizer is like the <code>standard</code> tokenizer except that it recognises URLs and email addresses as single tokens.</p>
<p><strong>Classic Tokenizer</strong></p>
<p>The <code>classic</code> tokenizer is a grammar based tokenizer for the English Language.</p>
<p><strong>Thai Tokenizer</strong></p>
<p>The <code>thai</code> tokenizer segments Thai text into words.</p>
<p><strong>谷歌翻译之后</strong></p>
<h4 id="标准分词器"><a href="#标准分词器" class="headerlink" title="标准分词器"></a><strong>标准分词器</strong></h4><p>标准分词器将文本划分为单词边界上的术语，这由Unicode文本分段算法定义。 它删除大多数标点符号。 这是大多数语言的最佳选择。 注意标点符号回进行过滤</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;I have, photos&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>配置：</p>
<table>
<thead>
<tr>
<th><code>max_token_length</code></th>
<th>The maximum token length. If a token is seen that exceeds this length then it is split at <code>max_token_length</code> intervals. Defaults to <code>255</code>.</th>
</tr>
</thead>
<tbody><tr>
<td>最大分词数</td>
<td>允许设置最大分次数，如果分词长度超过最大分词数，将会进行切割作为下一个分词。默认为255</td>
</tr>
</tbody></table>
<h4 id="字母分词器"><a href="#字母分词器" class="headerlink" title="字母分词器"></a><strong>字母分词器</strong></h4><p>字母分词器在遇到非字母字符时会将文本分为多个术语</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;letter&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog&#39;s bone&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[ The, QUICK, Brown, Foxes, jumped, over, the, lazy, dog, s, bone ]</span><br></pre></td></tr></table></figure>

<p>该<code>letter</code>分词器是不可配置</p>
<h4 id="小写分词器"><a href="#小写分词器" class="headerlink" title="小写分词器"></a><strong>小写分词器</strong></h4><p>小写分词器与字母分词器一样，在遇到非字母的字符时，会将文本分为多个词，但所有词都小写。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">POST _analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;lowercase&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog&#39;s bone.&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>该<code>letter</code>分词器是不可配置</p>
<h4 id="空格分词器"><a href="#空格分词器" class="headerlink" title="空格分词器"></a><strong>空格分词器</strong></h4><p>每当遇到任何空白字符时，空白令牌生成器都会将文本划分为多个术语。(但是不会对大小写进行转化，只判断空白字符)</p>
<p>配置：</p>
<table>
<thead>
<tr>
<th><code>max_token_length</code></th>
<th>The maximum token length. If a token is seen that exceeds this length then it is split at <code>max_token_length</code> intervals. Defaults to <code>255</code>.</th>
</tr>
</thead>
<tbody><tr>
<td>最大分词数</td>
<td>允许设置最大分次数，如果分词长度超过最大分词数，将会进行切割作为下一个分词。默认为255</td>
</tr>
</tbody></table>
<h4 id="UAX-URL电子邮件令牌生成器"><a href="#UAX-URL电子邮件令牌生成器" class="headerlink" title="UAX URL电子邮件令牌生成器"></a>UAX URL电子邮件令牌生成器</h4><p><strong>uax_url_email</strong> 分词器类似于标准令牌生成器，不同之处在于它将URL和电子邮件地址识别为单个分词。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">POST _analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;uax_url_email&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;Email me at john.smith@global-international.com&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>注意分词出来的email类型为</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;token&quot;: &quot;john.smith@global-international.com&quot;,</span><br><span class="line">    &quot;start_offset&quot;: 12,</span><br><span class="line">    &quot;end_offset&quot;: 47,</span><br><span class="line">    &quot;type&quot;: &quot;&lt;EMAIL&gt;&quot;,</span><br><span class="line">    &quot;position&quot;: 3</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>配置</p>
<table>
<thead>
<tr>
<th><code>max_token_length</code></th>
<th>The maximum token length. If a token is seen that exceeds this length then it is split at <code>max_token_length</code> intervals. Defaults to <code>255</code>.</th>
</tr>
</thead>
<tbody><tr>
<td>最大分词数</td>
<td>允许设置最大分次数，如果分词长度超过最大分词数，将会进行切割作为下一个分词。默认为255</td>
</tr>
</tbody></table>
<h4 id="经典分词器"><a href="#经典分词器" class="headerlink" title="经典分词器"></a>经典分词器</h4><p>经典的分词器是用于英语的基于语法的分词器。</p>
<blockquote>
<p>可以说是为英语而生的分词器. 这个分词器对于英文的首字符缩写、 公司名字、 email 、 大部分网站域名.都能很好的解决。 但是, 对于除了英语之外的其他语言，都不是很好使。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">POST _analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;classic&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog&#39;s bone.&quot;</span><br><span class="line">&#125;</span><br><span class="line">[ The, 2, QUICK, Brown, Foxes, jumped, over, the, lazy, dog&#39;s, bone ]</span><br></pre></td></tr></table></figure>

<p>下面是官方文档谷歌翻译</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">该&#96;classic&#96;标记生成器是一种基于语法标记生成器是好的英语语言文档。该令牌生成器具有试探法，可对首字母缩写词，公司名称，电子邮件地址和互联网主机名进行特殊处理。但是，这些规则并不总是有效，并且分词器不适用于英语以外的大多数其他语言：</span><br><span class="line"></span><br><span class="line">- 它最多将标点符号拆分为单词，删除标点符号。但是，不带空格的点被认为是令牌的一部分。</span><br><span class="line">- 除非令牌中没有数字，否则它将使用连字符对单词进行拆分，在这种情况下，整个令牌将被解释为产品编号，并且不会拆分。</span><br><span class="line">- 它将电子邮件地址和互联网主机名识别为一个令牌。</span><br></pre></td></tr></table></figure>

<p>配置：</p>
<table>
<thead>
<tr>
<th><code>max_token_length</code></th>
<th>The maximum token length. If a token is seen that exceeds this length then it is split at <code>max_token_length</code> intervals. Defaults to <code>255</code>.</th>
</tr>
</thead>
<tbody><tr>
<td>最大分词数</td>
<td>允许设置最大分次数，如果分词长度超过最大分词数，将会进行切割作为下一个分词。默认为255</td>
</tr>
</tbody></table>
<h4 id="泰语分词器"><a href="#泰语分词器" class="headerlink" title="泰语分词器"></a>泰语分词器</h4><p>泰语分词器将泰语文本分成单词。</p>
<h3 id="7-4-3-分词过滤器"><a href="#7-4-3-分词过滤器" class="headerlink" title="7.4.3 分词过滤器"></a>7.4.3 分词过滤器</h3><p>官方定义了大概20多种分词过滤，涵盖内容较多，以官方6.2.4文档为准</p>
<p><span class="exturl" data-url="aHR0cHM6Ly93d3cuZWxhc3RpYy5jby9ndWlkZS9lbi9lbGFzdGljc2VhcmNoL3JlZmVyZW5jZS82LjQvYW5hbHlzaXMtdG9rZW5maWx0ZXJzLmh0bWw=" title="https://www.elastic.co/guide/en/elasticsearch/reference/6.4/analysis-tokenfilters.html">https://www.elastic.co/guide/en/elasticsearch/reference/6.4/analysis-tokenfilters.html<i class="fa fa-external-link"></i></span></p>
<h4 id="标准分词过滤器"><a href="#标准分词过滤器" class="headerlink" title="标准分词过滤器"></a>标准分词过滤器</h4><p>不要以为有多牛逼，其实什么事情都没有干。在以后的版本中有可能扩展功能。只是单纯占位符</p>
<h4 id="ASCII-Folding-Token-Filter（ASCII折叠过滤器）"><a href="#ASCII-Folding-Token-Filter（ASCII折叠过滤器）" class="headerlink" title="ASCII Folding Token Filter（ASCII折叠过滤器）"></a>ASCII Folding Token Filter（ASCII折叠过滤器）</h4><p>官网翻译介绍：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">类型为asciifolding的分词过滤器，用于将前127个ASCII字符（“基本拉丁” Unicode块）中不存在的字母，数字和符号Unicode字符转换为等效的ASCII字符。 例：</span><br><span class="line">PUT &#x2F;asciifold_example</span><br><span class="line">&#123;</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">        &quot;analysis&quot; : &#123;</span><br><span class="line">            &quot;analyzer&quot; : &#123;</span><br><span class="line">                &quot;default&quot; : &#123;</span><br><span class="line">                    &quot;tokenizer&quot; : &quot;standard&quot;,</span><br><span class="line">                    &quot;filter&quot; : [&quot;standard&quot;, &quot;asciifolding&quot;]</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>允许进行如下配置：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;asciifold_example</span><br><span class="line">&#123;</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">        &quot;analysis&quot; : &#123;</span><br><span class="line">            &quot;analyzer&quot; : &#123;</span><br><span class="line">                &quot;default&quot; : &#123;</span><br><span class="line">                    &quot;tokenizer&quot; : &quot;standard&quot;,</span><br><span class="line">                    &quot;filter&quot; : [&quot;standard&quot;, &quot;my_ascii_folding&quot;]</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            &quot;filter&quot; : &#123;</span><br><span class="line">                &quot;my_ascii_folding&quot; : &#123;</span><br><span class="line">                    &quot;type&quot; : &quot;asciifolding&quot;,</span><br><span class="line">                    &quot;preserve_original&quot; : true --默认为false</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>翻译版</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">preserve_original： 接受默认值为false的preserve_original设置，但如果为true，则将保留原始令牌并发出折叠后的令牌</span><br></pre></td></tr></table></figure>

<h4 id="Flatten-Graph-Token-Filter（图形分词过滤器）"><a href="#Flatten-Graph-Token-Filter（图形分词过滤器）" class="headerlink" title="Flatten Graph Token Filter（图形分词过滤器）"></a>Flatten Graph Token Filter（图形分词过滤器）</h4><blockquote>
<p>注意：此功能在Lucene中被标记为实验性的</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">flatten_graph令牌过滤器接受任意图形令牌流，例如“同义词图形令牌过滤器”生成的图形令牌流，并将其展平为适合索引的单个线性令牌链。</span><br><span class="line"></span><br><span class="line">这是一个有损耗的过程，因为单独的边路径相互挤压，但是在索引过程中使用图形令牌流时是必需的，因为Lucene索引当前无法表示图形。 因此，最好仅在搜索时应用图形分析器，因为这样可以保留完整的图形结构并为接近查询提供正确的匹配项。</span><br><span class="line"></span><br><span class="line">有关此主题及其复杂性的更多信息，请阅读Lucene的TokenStreams实际上是图博客文章。</span><br></pre></td></tr></table></figure>

<h4 id="Length-Token-Filter（长度分词过滤器）"><a href="#Length-Token-Filter（长度分词过滤器）" class="headerlink" title="Length Token Filter（长度分词过滤器）"></a>Length Token Filter（长度分词过滤器）</h4><p>将超出最短和最长限制范围的单词过滤掉，如min=2，max=8，不在此范围的单词都会进行过滤</p>
<p>配置项如下</p>
<table>
<thead>
<tr>
<th><code>min</code></th>
<th>The minimum number. Defaults to <code>0</code>.</th>
</tr>
</thead>
<tbody><tr>
<td><strong>max</strong></td>
<td><strong>The maximum number. Defaults to <code>Integer.MAX_VALUE</code>, which is <code>2^31-1</code> or 2147483647.</strong></td>
</tr>
</tbody></table>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;length-filter</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;: &#123;</span><br><span class="line">    &quot;analysis&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;myfilter&quot;:&#123;</span><br><span class="line">          &quot;type&quot;: &quot;length&quot;,</span><br><span class="line">          &quot;max&quot;: 8,</span><br><span class="line">          &quot;min&quot;: 2</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;, </span><br><span class="line">      &quot;analyzer&quot;: &#123;</span><br><span class="line">        &quot;defulat&quot;: &#123;</span><br><span class="line">          &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">          &quot;filter&quot;: [&quot;standard&quot;, &quot;myfilter&quot;]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果如下:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;acknowledged&quot;: true,</span><br><span class="line">  &quot;shards_acknowledged&quot;: true,</span><br><span class="line">  &quot;index&quot;: &quot;length-filter&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="Lowercase-token-filter（小写分词过滤器）"><a href="#Lowercase-token-filter（小写分词过滤器）" class="headerlink" title="Lowercase token filter（小写分词过滤器）"></a>Lowercase token filter（小写分词过滤器）</h4><p>可以讲任何经过的分词变成小写</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;lowercase_example</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;: &#123;</span><br><span class="line">    &quot;analysis&quot;: &#123;</span><br><span class="line">      &quot;analyzer&quot;: &#123;</span><br><span class="line">        &quot;standard_lowercase_example&quot;: &#123;</span><br><span class="line">          &quot;type&quot;: &quot;custom&quot;,</span><br><span class="line">          &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">          &quot;filter&quot;: [&quot;lowercase&quot;]</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;greek_lowercase_example&quot;: &#123;</span><br><span class="line">          &quot;type&quot;: &quot;custom&quot;,</span><br><span class="line">          &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">          &quot;filter&quot;: [&quot;greek_lowercase&quot;]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;greek_lowercase&quot;: &#123;</span><br><span class="line">          &quot;type&quot;: &quot;lowercase&quot;,</span><br><span class="line">          &quot;language&quot;: &quot;greek&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="Uppercase-Token-Filter（大写分词过滤器）"><a href="#Uppercase-Token-Filter（大写分词过滤器）" class="headerlink" title="Uppercase Token Filter（大写分词过滤器）"></a>Uppercase Token Filter（大写分词过滤器）</h4><p>讲所有经过的分词转大写</p>
<h4 id="NGram-Token-Filter（N元语法过滤器）"><a href="#NGram-Token-Filter（N元语法过滤器）" class="headerlink" title="NGram Token Filter（N元语法过滤器）"></a>NGram Token Filter（N元语法过滤器）</h4><table>
<thead>
<tr>
<th>Setting</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td><code>min_gram</code></td>
<td>Defaults to <code>1</code>.</td>
</tr>
<tr>
<td><code>max_gram</code></td>
<td>Defaults to <code>2</code>.</td>
</tr>
</tbody></table>
<p>索引级别设置index.max_ngram_diff控制max_gram和min_gram之间的最大允许差异。</p>
<p>N元语法过滤器即：</p>
<p>控制被切分单词的数量</p>
<p>举例：</p>
<blockquote>
<ol>
<li><strong>1-grams</strong>:一元语法过滤器</li>
</ol>
<p>以：＂spaghetti＂为例：</p>
<p>ｓ　ｐ　ａ　ｇ　ｈ　ｅ　ｔ　ｔ　ｉ</p>
<ol>
<li><p>二元语法过滤器</p>
<p>将会拆分为: sp，pa，ag，gh，he，et，tt，ti</p>
</li>
<li><p>三元语法过滤器</p>
<p>将会拆分为：spa，pag，agh，ghe，het，ett，tti</p>
</li>
</ol>
</blockquote>
<h4 id="Edge-NGram-Token-Filter（侧边N元语法过滤器）"><a href="#Edge-NGram-Token-Filter（侧边N元语法过滤器）" class="headerlink" title="Edge NGram Token Filter（侧边N元语法过滤器）"></a>Edge NGram Token Filter（侧边N元语法过滤器）</h4><table>
<thead>
<tr>
<th>Setting</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td><code>min_gram</code></td>
<td>Defaults to <code>1</code>.</td>
</tr>
<tr>
<td><code>max_gram</code></td>
<td>Defaults to <code>2</code>.</td>
</tr>
<tr>
<td><code>side</code></td>
<td>deprecated. Either <code>front</code> or <code>back</code>. Defaults to <code>front</code>.</td>
</tr>
</tbody></table>
<p>为N元语法的变体：</p>
<p>仅仅从边缘构建N元语法</p>
<p>如:min = 2 ,max = 6</p>
<p>“spaghetti” 将会切分为： sp spa spag spagh spaghe</p>
<h3 id="7-4-4-N元语法的使用场景以及使用案例"><a href="#7-4-4-N元语法的使用场景以及使用案例" class="headerlink" title="7.4.4 N元语法的使用场景以及使用案例"></a>7.4.4 N元语法的使用场景以及使用案例</h3><p>N元语法过滤器主要是可以用于处理因为的错误单词拼写，将单词进行切分组合，匹配相同的部分，这能保证即使错误的书写依然可以进行正确的匹配，但是中文的拼写修改有待进一步学习</p>
<p>当不知道是什么语言的时候，N元语法是一种很好的文本分析方式：</p>
<p>可以分析单词之间没有空格的单词！！！</p>
<p>指定依然靠min和max这两个重要参数</p>
<h4 id="使用案例"><a href="#使用案例" class="headerlink" title="使用案例:"></a>使用案例:</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;n-gram-filter</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;: &#123;</span><br><span class="line">    &quot;analysis&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;myfilter&quot;:&#123;</span><br><span class="line">          &quot;type&quot;: &quot;ngram&quot;,</span><br><span class="line">          &quot;min_gram&quot;: 2,</span><br><span class="line">          &quot;max_gram&quot;: 6</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;, </span><br><span class="line">      &quot;analyzer&quot;: &#123;</span><br><span class="line">        &quot;defulat&quot;: &#123;</span><br><span class="line">          &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">          &quot;filter&quot;: [&quot;standard&quot;, &quot;myfilter&quot;]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果：会出现一个报错提示官方已经弃用这两个参数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Deprecation: Deprecated big difference between max_gram and min_gram in NGram Tokenizer,expected difference must be less than or equal to: [1]</span><br></pre></td></tr></table></figure>

<p>有关该问题的社区讨论</p>
<p><span class="exturl" data-url="aHR0cHM6Ly9kaXNjdXNzLmVsYXN0aWMuY28vdC9kZXByZWNhdGlvbi1kZXByZWNhdGVkLWJpZy1kaWZmZXJlbmNlLWJldHdlZW4tbWF4LWdyYW0tYW5kLW1pbi1ncmFtLWluLW5ncmFtLzEyMjk2OQ==" title="https://discuss.elastic.co/t/deprecation-deprecated-big-difference-between-max-gram-and-min-gram-in-ngram/122969">https://discuss.elastic.co/t/deprecation-deprecated-big-difference-between-max-gram-and-min-gram-in-ngram/122969<i class="fa fa-external-link"></i></span></p>
<h4 id="Shingle-Token-Filter（滑动窗口分词过滤器）"><a href="#Shingle-Token-Filter（滑动窗口分词过滤器）" class="headerlink" title="Shingle Token Filter（滑动窗口分词过滤器）"></a><span class="exturl" data-url="aHR0cHM6Ly93d3cuZWxhc3RpYy5jby9ndWlkZS9lbi9lbGFzdGljc2VhcmNoL3JlZmVyZW5jZS82LjQvYW5hbHlzaXMtc2hpbmdsZS10b2tlbmZpbHRlci5odG1s" title="https://www.elastic.co/guide/en/elasticsearch/reference/6.4/analysis-shingle-tokenfilter.html">Shingle Token Filter<i class="fa fa-external-link"></i></span>（滑动窗口分词过滤器）</h4><h2 id="7-5-提取词干"><a href="#7-5-提取词干" class="headerlink" title="7.5 提取词干"></a>7.5 提取词干</h2><h3 id="7-5-1-算分提取词干"><a href="#7-5-1-算分提取词干" class="headerlink" title="7.5.1 算分提取词干"></a>7.5.1 算分提取词干</h3><p>es提供三种算法词干：</p>
<ol>
<li>snowball 过滤器</li>
<li>porter stem 过滤器</li>
<li>kstem 过滤器</li>
</ol>
<h4 id="选取kstem-作为案例测试"><a href="#选取kstem-作为案例测试" class="headerlink" title="选取kstem 作为案例测试"></a>选取kstem 作为案例测试</h4><h3 id="7-5-2-使用字典提取词干"><a href="#7-5-2-使用字典提取词干" class="headerlink" title="7.5.2 使用字典提取词干"></a>7.5.2 使用字典提取词干</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">DELETE &#x2F;kstem-filter</span><br><span class="line"></span><br><span class="line">PUT &#x2F;kstem-filter</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;: &#123;</span><br><span class="line">    &quot;analysis&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;myfilter&quot;:&#123;</span><br><span class="line">          &quot;type&quot;: &quot;kstem&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;, </span><br><span class="line">      &quot;analyzer&quot;: &#123;</span><br><span class="line">        &quot;defulat&quot;: &#123;</span><br><span class="line">          &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">          &quot;filter&quot;: [&quot;lowercase&quot;, &quot;myfilter&quot;]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET kstem-filter&#x2F;_settings</span><br></pre></td></tr></table></figure>

<h1 id="8-使用相关性进行搜索"><a href="#8-使用相关性进行搜索" class="headerlink" title="8. 使用相关性进行搜索"></a>8. 使用相关性进行搜索</h1><h2 id="8-1-es-的打分机制"><a href="#8-1-es-的打分机制" class="headerlink" title="8.1 es 的打分机制"></a>8.1 es 的打分机制</h2><h3 id="8-1-1-文档是如何运作的："><a href="#8-1-1-文档是如何运作的：" class="headerlink" title="8.1.1 文档是如何运作的："></a>8.1.1 文档是如何运作的：</h3><p>默认使用的是<strong>词频-逆文档</strong>（TF-IDF）词频</p>
<p>TF：词频</p>
<p>IDF：逆文档频率</p>
<h3 id="8-1-2-词频"><a href="#8-1-2-词频" class="headerlink" title="8.1.2 词频"></a>8.1.2 词频</h3><p>词条在文本当中出现的次数</p>
<h3 id="8-1-3-逆文档词频"><a href="#8-1-3-逆文档词频" class="headerlink" title="8.1.3 逆文档词频"></a>8.1.3 逆文档词频</h3><p>如果一个分词在索引的不同文档中出现的次数越多， 就越<strong>不重要</strong></p>
<blockquote>
<ul>
<li>文档频率的逆源自得分乘以 1/DF , DF是文档频率。意味着越高频率得分就会越低</li>
<li>逆文档频率只关心“是否”</li>
</ul>
</blockquote>
<h3 id="8-1-4-Lucene-评分公式"><a href="#8-1-4-Lucene-评分公式" class="headerlink" title="8.1.4 Lucene 评分公式"></a>8.1.4 Lucene 评分公式</h3><ul>
<li>词频</li>
<li>逆文档频率</li>
<li>调和因子<ul>
<li>搜索过多少文档以及发现多少词条</li>
</ul>
</li>
<li>查询标准化<ul>
<li>试图让不同的查询结果具有可比性</li>
</ul>
</li>
</ul>
<h2 id="8-2-其他打分方式"><a href="#8-2-其他打分方式" class="headerlink" title="8.2 其他打分方式"></a>8.2 其他打分方式</h2><ul>
<li>Okapi BM25</li>
<li>随机性分歧，DFR相似度</li>
<li>基于信息，IB相似度</li>
<li>LM Dirichlet 相似度</li>
<li>LM Jelinek Mercer 相似度</li>
</ul>
<h3 id="如何指定索引的打分方式？"><a href="#如何指定索引的打分方式？" class="headerlink" title="如何指定索引的打分方式？"></a>如何指定索引的打分方式？</h3><ul>
<li><p>修改字段映射的similarity 参数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;take_score</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;: &#123;</span><br><span class="line">    &quot;number_of_shards&quot;: 2,</span><br><span class="line">    &quot;number_of_replicas&quot;: 1</span><br><span class="line">  &#125;, </span><br><span class="line">  &quot;mappings&quot;: &#123;</span><br><span class="line">    &quot;mytype&quot;:&#123;</span><br><span class="line">      &quot;properties&quot;: &#123;</span><br><span class="line">        &quot;title&quot;:&#123;</span><br><span class="line">          &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">          &quot;similarity&quot;: &quot;defualt&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">或者</span><br><span class="line"></span><br><span class="line">PUT &#x2F;like</span><br><span class="line">&#123;</span><br><span class="line">  &quot;mappings&quot;: &#123;</span><br><span class="line">    &quot;get-together&quot;:&#123;</span><br><span class="line">      &quot;properties&quot;: &#123;</span><br><span class="line">        &quot;tilte&quot;: &#123;</span><br><span class="line">          &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">          &quot;similarity&quot;: &quot;BM25&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>在settings 中扩展，为某个索引设置打分算法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;dislike</span><br><span class="line">&#123;</span><br><span class="line">&quot;settings&quot;: &#123;</span><br><span class="line">    &quot;similarity&quot;: &#123;</span><br><span class="line">      &quot;my_custom&quot;: &#123;</span><br><span class="line">        &quot;type&quot;: &quot;BM25&quot;,</span><br><span class="line">        &quot;k1&quot;: 1.2,</span><br><span class="line">        &quot;b&quot;: 0.75,</span><br><span class="line">        &quot;discount_overlaps&quot;: false</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">GET &#x2F;dislike&#x2F;_settings</span><br></pre></td></tr></table></figure>

<blockquote>
<p>重要改变：6.0以后官方已不提倡使用TF-IDF，因为该评分方式已经不适用与当今时代的实际需要，官方推荐使用BM25，并且建议7.0 以后的版本移除TF-IDF算法的所有内容，所以TF-IDF这种打分机制只做了解即可</p>
</blockquote>
</li>
</ul>
<h2 id="8-3-索引期间Boosting"><a href="#8-3-索引期间Boosting" class="headerlink" title="8.3 索引期间Boosting"></a>8.3 索引期间Boosting</h2><p>不推荐在创建索引的时候使用Boosting, 而是在查询的时候,原因如下</p>
<ul>
<li>缺少灵活性</li>
<li>以低精度的数值在Lucene 的内部索引结构当中，只有一个字节存储，可能丢失精度</li>
<li>boost 是运用于一个词条，配上多个词条，就意味着多次的boost， 进一步增加权重</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;my-gettogether</span><br><span class="line">&#123;</span><br><span class="line">  &quot;mappings&quot;: &#123;</span><br><span class="line">    &quot;groups&quot;: &#123;</span><br><span class="line">      &quot;properties&quot;: &#123;</span><br><span class="line">        &quot;name&quot;:&#123;</span><br><span class="line">          &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">          &quot;boost&quot;: 2.0</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">GET &#x2F;my-gettogether&#x2F;_mapping</span><br></pre></td></tr></table></figure>

<h2 id="8-4-查询期间的Boosting"><a href="#8-4-查询期间的Boosting" class="headerlink" title="8.4 查询期间的Boosting"></a>8.4 查询期间的Boosting</h2><ul>
<li>match、multi_match、simple_query_string、query_string</li>
<li>funcation_score (更为精确)</li>
</ul>
<p>使用match 查询进行boosting</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;should&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;match&quot;: &#123;</span><br><span class="line">            &quot;about&quot;: &#123;</span><br><span class="line">              &quot;query&quot;: &quot;i hide&quot;,</span><br><span class="line">              &quot;boost&quot;: 2.5</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;match&quot;: &#123;</span><br><span class="line">            &quot;last_name&quot;: &#123;</span><br><span class="line">              &quot;query&quot;: &quot;Simith&quot;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>第一个match 将会比第二个match 查询有更大的影响力</p>
<h3 id="8-4-1-跨越多个字段的查询"><a href="#8-4-1-跨越多个字段的查询" class="headerlink" title="8.4.1 跨越多个字段的查询"></a>8.4.1 跨越多个字段的查询</h3><h3 id="8-4-2-使用multi-match-查询，指定整个Boost"><a href="#8-4-2-使用multi-match-查询，指定整个Boost" class="headerlink" title="8.4.2 使用multi_match 查询，指定整个Boost"></a>8.4.2 使用multi_match 查询，指定整个Boost</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;multi_match&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &quot;smit wang&quot;,</span><br><span class="line">      &quot;fields&quot;: [&quot;first_name&quot;, &quot;last_name&quot;],</span><br><span class="line">      &quot;boost&quot;: 2.5</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="8-4-3-使用特殊符号-对于name-进行boost"><a href="#8-4-3-使用特殊符号-对于name-进行boost" class="headerlink" title="8.4.3 使用特殊符号^对于name 进行boost"></a>8.4.3 使用特殊符号^对于name 进行boost</h3><p>使用3倍boost 修改某个字段查询的Boost</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;multi_match&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &quot;long&quot;,</span><br><span class="line">      &quot;fields&quot;: [&quot;name^3&quot;]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="8-4-4-query-string-中对于针对单个的词条进行boost"><a href="#8-4-4-query-string-中对于针对单个的词条进行boost" class="headerlink" title="8.4.4 query_string 中对于针对单个的词条进行boost"></a>8.4.4 query_string 中对于针对单个的词条进行boost</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">POST myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &quot;lixiao* OR *long^3&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>一个字段被boost 4 倍，并不是意味着得分会乘以4，所以得分不是按照严格的乘法</p>
<h2 id="8-5-使用”解释-explain-”来理解文档评分"><a href="#8-5-使用”解释-explain-”来理解文档评分" class="headerlink" title="8.5 使用”解释(explain)”来理解文档评分"></a>8.5 使用”解释(explain)”来理解文档评分</h2><ul>
<li>请求体 expliane = true 告诉es 运行解释操作</li>
<li>Url指定_explain</li>
</ul>
<p>下面为请求体重设置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">POST myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &quot;lixiao* OR *long^3&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;explain&quot;: true</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果，内容较为庞大，不过应该不是很难懂</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;took&quot;: 58,</span><br><span class="line">  &quot;timed_out&quot;: false,</span><br><span class="line">  &quot;_shards&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 5,</span><br><span class="line">    &quot;successful&quot;: 5,</span><br><span class="line">    &quot;skipped&quot;: 0,</span><br><span class="line">    &quot;failed&quot;: 0</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;hits&quot;: &#123;</span><br><span class="line">    &quot;total&quot;: 3,</span><br><span class="line">    &quot;max_score&quot;: 4,</span><br><span class="line">    &quot;hits&quot;: [</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_shard&quot;: &quot;[myindex][2]&quot;,</span><br><span class="line">        &quot;_node&quot;: &quot;Q58S9K26RxqIiVA-UQNrgg&quot;,</span><br><span class="line">        &quot;_index&quot;: &quot;myindex&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;test&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;Fbggy20B5sayAd6PVrE2&quot;,</span><br><span class="line">        &quot;_score&quot;: 4,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">          &quot;age&quot;: 5,</span><br><span class="line">          &quot;birthday&quot;: &quot;2019-05-04&quot;,</span><br><span class="line">          &quot;test_field&quot;: &quot;zzzzzz&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;_explanation&quot;: &#123;</span><br><span class="line">          &quot;value&quot;: 4, # 最后得分</span><br><span class="line">          &quot;description&quot;: &quot;sum of:&quot;,</span><br><span class="line">          &quot;details&quot;: [</span><br><span class="line">            &#123;</span><br><span class="line">              &quot;value&quot;: 1,</span><br><span class="line">              &quot;description&quot;: &quot;max of:&quot;,</span><br><span class="line">              &quot;details&quot;: [</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 1,</span><br><span class="line">                  &quot;description&quot;: &quot;name:lixiao*&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;,</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 1,</span><br><span class="line">                  &quot;description&quot;: &quot;name.keyword:lixiao*&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;</span><br><span class="line">              ]</span><br><span class="line">            &#125;,</span><br><span class="line">            &#123;</span><br><span class="line">              &quot;value&quot;: 3,</span><br><span class="line">              &quot;description&quot;: &quot;max of:&quot;,</span><br><span class="line">              &quot;details&quot;: [</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 3,</span><br><span class="line">                  &quot;description&quot;: &quot;name:*long^3.0&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;,</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 3,</span><br><span class="line">                  &quot;description&quot;: &quot;name.keyword:*long^3.0&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;</span><br><span class="line">              ]</span><br><span class="line">            &#125;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_shard&quot;: &quot;[myindex][3]&quot;,</span><br><span class="line">        &quot;_node&quot;: &quot;Q58S9K26RxqIiVA-UQNrgg&quot;,</span><br><span class="line">        &quot;_index&quot;: &quot;myindex&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;test&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;1&quot;,</span><br><span class="line">        &quot;_score&quot;: 4,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">          &quot;age&quot;: 55,</span><br><span class="line">          &quot;birthday&quot;: &quot;2019-05-04&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;_explanation&quot;: &#123;</span><br><span class="line">          &quot;value&quot;: 4,</span><br><span class="line">          &quot;description&quot;: &quot;sum of:&quot;,</span><br><span class="line">          &quot;details&quot;: [</span><br><span class="line">            &#123;</span><br><span class="line">              &quot;value&quot;: 1,</span><br><span class="line">              &quot;description&quot;: &quot;max of:&quot;,</span><br><span class="line">              &quot;details&quot;: [</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 1,</span><br><span class="line">                  &quot;description&quot;: &quot;name:lixiao*&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;,</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 1,</span><br><span class="line">                  &quot;description&quot;: &quot;name.keyword:lixiao*&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;</span><br><span class="line">              ]</span><br><span class="line">            &#125;,</span><br><span class="line">            &#123;</span><br><span class="line">              &quot;value&quot;: 3,</span><br><span class="line">              &quot;description&quot;: &quot;max of:&quot;,</span><br><span class="line">              &quot;details&quot;: [</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 3,</span><br><span class="line">                  &quot;description&quot;: &quot;name:*long^3.0&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;,</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 3,</span><br><span class="line">                  &quot;description&quot;: &quot;name.keyword:*long^3.0&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;</span><br><span class="line">              ]</span><br><span class="line">            &#125;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        &quot;_shard&quot;: &quot;[myindex][3]&quot;,</span><br><span class="line">        &quot;_node&quot;: &quot;Q58S9K26RxqIiVA-UQNrgg&quot;,</span><br><span class="line">        &quot;_index&quot;: &quot;myindex&quot;,</span><br><span class="line">        &quot;_type&quot;: &quot;test&quot;,</span><br><span class="line">        &quot;_id&quot;: &quot;FLjrym0B5sayAd6PrrGN&quot;,</span><br><span class="line">        &quot;_score&quot;: 3,</span><br><span class="line">        &quot;_source&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;CHENLONG&quot;,</span><br><span class="line">          &quot;age&quot;: 15,</span><br><span class="line">          &quot;birthday&quot;: &quot;2011-02-14&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;_explanation&quot;: &#123;</span><br><span class="line">          &quot;value&quot;: 3,</span><br><span class="line">          &quot;description&quot;: &quot;sum of:&quot;,</span><br><span class="line">          &quot;details&quot;: [</span><br><span class="line">            &#123;</span><br><span class="line">              &quot;value&quot;: 3,</span><br><span class="line">              &quot;description&quot;: &quot;max of:&quot;,</span><br><span class="line">              &quot;details&quot;: [</span><br><span class="line">                &#123;</span><br><span class="line">                  &quot;value&quot;: 3,</span><br><span class="line">                  &quot;description&quot;: &quot;name:*long^3.0&quot;,</span><br><span class="line">                  &quot;details&quot;: []</span><br><span class="line">                &#125;</span><br><span class="line">              ]</span><br><span class="line">            &#125;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>从改结果中我们其实可以了解到：</p>
<p>es 官方的分析内容表示官方其实已经将原有的TF-IDF(词频-逆文档频率)进行移除</p>
<p>现在默认使用的是BM25</p>
<p>并无法进行yml配置操作</p>
</blockquote>
<h3 id="8-5-1-解释一篇文档不匹配的原因"><a href="#8-5-1-解释一篇文档不匹配的原因" class="headerlink" title="8.5.1 解释一篇文档不匹配的原因"></a>8.5.1 解释一篇文档不匹配的原因</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;test&#x2F;5&#x2F;_explain</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;:&#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &quot;xiaolong&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="8-6-使用查询再打分来减小评分操作影响"><a href="#8-6-使用查询再打分来减小评分操作影响" class="headerlink" title="8.6 使用查询再打分来减小评分操作影响"></a>8.6 使用查询再打分来减小评分操作影响</h2><h3 id="8-6-1-官方文档介绍-6-2版本"><a href="#8-6-1-官方文档介绍-6-2版本" class="headerlink" title="8.6.1 官方文档介绍 6.2版本"></a>8.6.1 官方文档介绍 6.2版本</h3><p><span class="exturl" data-url="aHR0cHM6Ly93d3cuZWxhc3RpYy5jby9ndWlkZS9lbi9lbGFzdGljc2VhcmNoL3JlZmVyZW5jZS82LjIvc2VhcmNoLXJlcXVlc3QtcmVzY29yZS5odG1s" title="https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-request-rescore.html">https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-request-rescore.html<i class="fa fa-external-link"></i></span></p>
<ul>
<li>使用脚本评分</li>
<li>进行phrase 查询，搜索一段距离内的单词，使用很大的slop值</li>
</ul>
<p>使用es的再打分特性，计算返回结果集合的第二轮计算得分</p>
<h3 id="8-6-2-使用rescore-特性，对于匹配文档子集再评分"><a href="#8-6-2-使用rescore-特性，对于匹配文档子集再评分" class="headerlink" title="8.6.2 使用rescore 特性，对于匹配文档子集再评分"></a>8.6.2 使用rescore 特性，对于匹配文档子集再评分</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &quot;lixiao* OR *long^3&quot;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;rescore&quot;: &#123;</span><br><span class="line">    &quot;window_size&quot;: 20,</span><br><span class="line">    &quot;query&quot;: &#123;</span><br><span class="line">      &quot;rescore_query&quot;: &#123;</span><br><span class="line">        &quot;match_phrase&quot;:&#123;</span><br><span class="line">          &quot;name&quot;: &#123;</span><br><span class="line">            &quot;query&quot;: &quot;li&quot;,</span><br><span class="line">            &quot;slop&quot;: 5</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;query_weight&quot;: 0.8,</span><br><span class="line">      &quot;rescore_query_weight&quot;: 1.3</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>query_weight：初始查询得分权重</p>
<p>rescore_query_weight：再评分查询得分权重</p>
<h2 id="8-7-function-score-来定制得分"><a href="#8-7-function-score-来定制得分" class="headerlink" title="8.7 function_score 来定制得分"></a>8.7 function_score 来定制得分</h2><h3 id="8-7-1-function-score-的基本结构"><a href="#8-7-1-function-score-的基本结构" class="headerlink" title="8.7.1 function_score 的基本结构"></a>8.7.1 function_score 的基本结构</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;function_score&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &#123;</span><br><span class="line">        &quot;match&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;lixiaolong&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;functions&quot;: [</span><br><span class="line">        </span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="8-7-2-weight-函数"><a href="#8-7-2-weight-函数" class="headerlink" title="8.7.2 weight 函数"></a>8.7.2 weight 函数</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;function_score&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &#123;</span><br><span class="line">        &quot;match_phrase&quot;: &#123;</span><br><span class="line">          &quot;name&quot;:&#123;</span><br><span class="line">            &quot;query&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">            &quot;slop&quot;: 5</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;functions&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;weight&quot;: 3</span><br><span class="line">          &quot;filter&quot;: &#123;</span><br><span class="line">            &quot;term&quot;: &#123;</span><br><span class="line">              &quot;age&quot;: 5</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>大致意识是将过滤出age =5 的文档将权重加3倍</p>
<h4 id="可以指定多个weight函数"><a href="#可以指定多个weight函数" class="headerlink" title="可以指定多个weight函数"></a>可以指定多个weight函数</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;function_score&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &#123;</span><br><span class="line">        &quot;match_phrase&quot;: &#123;</span><br><span class="line">          &quot;name&quot;:&#123;</span><br><span class="line">            &quot;query&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">            &quot;slop&quot;: 5</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;functions&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;weight&quot;: 1.5,</span><br><span class="line">          &quot;filter&quot;: &#123;</span><br><span class="line">            &quot;term&quot;: &#123;</span><br><span class="line">              &quot;age&quot;: 5</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;weight&quot;: 1.8,</span><br><span class="line">          &quot;filter&quot;: &#123;</span><br><span class="line">            &quot;term&quot;: &#123;</span><br><span class="line">              &quot;test_field&quot;: &quot;zzzzzz&quot;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="8-7-3-合并得分"><a href="#8-7-3-合并得分" class="headerlink" title="8.7.3 合并得分"></a>8.7.3 合并得分</h3><p>得分合并的两种因素：</p>
<ul>
<li>从每个单独的函数而来的分数如何合并，score_mode</li>
<li>从函数而来的得分如何同原始查询得分合并，boost_mode</li>
</ul>
<p>第一个因素称为score_mode 参数， 处理不同函数得分如何合并</p>
<p>可以设置的参数如下</p>
<ul>
<li>multiply</li>
<li>sum</li>
<li>avg</li>
<li>first</li>
<li>max</li>
<li>min</li>
</ul>
<p>默认是得分相乘 multiply</p>
<p>如果设置为first,则会优先选择第一个匹配的Boost因子</p>
<p>第二种得分合并设置，称为boost_mode。控制原始查询的得分和函数得分如何合并</p>
<p>可以设置的参数如下:</p>
<ul>
<li>sum</li>
<li>avg</li>
<li>max</li>
<li>min</li>
<li>replayce</li>
</ul>
<p>默认为初始查询得分和函数得分相乘</p>
<p>设置为replace 则原有的查询被函数得分替换</p>
<h3 id="8-7-4-field-value-factor-函数"><a href="#8-7-4-field-value-factor-函数" class="headerlink" title="8.7.4 field_value_factor 函数"></a>8.7.4 field_value_factor 函数</h3><p>该函数将包含数值的字段的名称作为输入，选择性的乘以常熟，然后进行数学运算</p>
<h3 id="8-7-5-在function-score-查询中使用field-value-factor"><a href="#8-7-5-在function-score-查询中使用field-value-factor" class="headerlink" title="8.7.5 在function_score 查询中使用field_value_factor"></a>8.7.5 在function_score 查询中使用field_value_factor</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;function_score&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &#123;</span><br><span class="line">        &quot;match&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;lixiaolong&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;functions&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;field_value_factor&quot;: &#123;</span><br><span class="line">            &quot;field&quot;: &quot;age&quot;,</span><br><span class="line">            &quot;factor&quot;: 1.2, </span><br><span class="line">            &quot;modifier&quot;: &quot;ln&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>modifier 可选参数：</p>
<ul>
<li>none (默认)</li>
<li>log</li>
<li>log1p</li>
<li>log2p</li>
<li>ln1p</li>
<li>ln2p</li>
<li>square</li>
<li>sqrt</li>
<li>reciprocal</li>
<li>ln</li>
</ul>
<h2 id="8-8-painless脚本-5-0后go语言脚本支持已删除"><a href="#8-8-painless脚本-5-0后go语言脚本支持已删除" class="headerlink" title="8.8 painless脚本(5.0后go语言脚本支持已删除)"></a>8.8 painless脚本(5.0后go语言脚本支持已删除)</h2><p>使用一个脚本进行评分</p>
<p>5.0 之后已经将go语言等脚本移除，使用Lucene官方指定的脚本语言 painless 类js语言</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;function_score&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;lixiaolong&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;functions&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;script_score&quot;: &#123;</span><br><span class="line">            &quot;script&quot;: &#123;</span><br><span class="line">              &quot;lang&quot;: &quot;painless&quot;, </span><br><span class="line">              &quot;params&quot;: &#123;</span><br><span class="line">                &quot;mytest&quot;:555</span><br><span class="line">              &#125;, </span><br><span class="line">              &quot;source&quot;: &quot;&quot;&quot;</span><br><span class="line">                int total &#x3D; 0;</span><br><span class="line">                for (int i &#x3D; 0; i &lt; doc[&#39;age&#39;].length; ++i) &#123;</span><br><span class="line">                  total +&#x3D; doc[&#39;age&#39;][i] + params.mytest;</span><br><span class="line">                &#125;</span><br><span class="line">                return total;</span><br><span class="line">              &quot;&quot;&quot;</span><br><span class="line">              </span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如果要引用params的值，需要使用params.xxx进行脚本的常量引用</p>
<h3 id="8-7-5-random-score-函数"><a href="#8-7-5-random-score-函数" class="headerlink" title="8.7.5 random_score 函数"></a>8.7.5 random_score 函数</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;function_score&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;name&quot;: &quot;lixiaolong&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      &quot;functions&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;random_score&quot;: &#123;</span><br><span class="line">            &quot;seed&quot;: 1234,</span><br><span class="line">            &quot;field&quot;: &quot;age&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>It was possible to set a seed without setting a field, but this has been deprecated as this requires loading fielddata on the <code>_id</code> field which consumes a lot of memory.</p>
</blockquote>
<p>注意需要指定field 对于文档字段的排序</p>
<p>否则会报一个必要参数提示</p>
<h3 id="8-7-6-衰减函数"><a href="#8-7-6-衰减函数" class="headerlink" title="8.7.6 衰减函数"></a>8.7.6 衰减函数</h3><ul>
<li>linear</li>
<li>gauss</li>
<li>exp</li>
</ul>
<h4 id="官方文档"><a href="#官方文档" class="headerlink" title="官方文档"></a>官方文档</h4><p><span class="exturl" data-url="aHR0cHM6Ly93d3cuZWxhc3RpYy5jby9ndWlkZS9lbi9lbGFzdGljc2VhcmNoL3JlZmVyZW5jZS82LjIvcXVlcnktZHNsLWZ1bmN0aW9uLXNjb3JlLXF1ZXJ5Lmh0bWwjZnVuY3Rpb24tZGVjYXk=" title="https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-function-score-query.html#function-decay">https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-function-score-query.html#function-decay<i class="fa fa-external-link"></i></span></p>
<p>官方配置案例如下:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">    &quot;query&quot;: &#123;</span><br><span class="line">        &quot;function_score&quot;: &#123;</span><br><span class="line">            &quot;gauss&quot;: &#123;</span><br><span class="line">                &quot;date&quot;: &#123;</span><br><span class="line">                      &quot;origin&quot;: &quot;2013-09-17&quot;, </span><br><span class="line">                      &quot;scale&quot;: &quot;10d&quot;,</span><br><span class="line">                      &quot;offset&quot;: &quot;5d&quot;, </span><br><span class="line">                      &quot;decay&quot; : 0.5 </span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="配置选项"><a href="#配置选项" class="headerlink" title="配置选项"></a>配置选项</h4><ul>
<li>origin：曲线原点，表示期望值。地理距离，日期或者数值型</li>
<li>offset：分数开始衰减的位置</li>
<li>scale 和 decay ：字段值为scale的时候，分数减少到指定的decay</li>
</ul>
<p>根据上面分析，从5天开始，到第10天的时候，衰减到原分数的0.5</p>
<h2 id="8-9-使用脚本排序"><a href="#8-9-使用脚本排序" class="headerlink" title="8.9 使用脚本排序"></a>8.9 使用脚本排序</h2><h1 id="9-Elasticsearch-REST-API-的学习使用"><a href="#9-Elasticsearch-REST-API-的学习使用" class="headerlink" title="9. Elasticsearch REST API 的学习使用"></a>9. Elasticsearch REST API 的学习使用</h1><h2 id="9-0-API官网"><a href="#9-0-API官网" class="headerlink" title="9.0 API官网"></a>9.0 API官网</h2><p>rest 低级 api：<span class="exturl" data-url="aHR0cHM6Ly9hcnRpZmFjdHMuZWxhc3RpYy5jby9qYXZhZG9jL29yZy9lbGFzdGljc2VhcmNoL2NsaWVudC9lbGFzdGljc2VhcmNoLXJlc3QtY2xpZW50LzYuMi40L29yZy9lbGFzdGljc2VhcmNoL2NsaWVudC9wYWNrYWdlLXN1bW1hcnkuaHRtbA==" title="https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client/6.2.4/org/elasticsearch/client/package-summary.html">https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-client/6.2.4/org/elasticsearch/client/package-summary.html<i class="fa fa-external-link"></i></span></p>
<p>rest 高级 api：<span class="exturl" data-url="aHR0cHM6Ly9hcnRpZmFjdHMuZWxhc3RpYy5jby9qYXZhZG9jL29yZy9lbGFzdGljc2VhcmNoL2NsaWVudC9lbGFzdGljc2VhcmNoLXJlc3QtaGlnaC1sZXZlbC1jbGllbnQvNi4yLjQvaW5kZXguaHRtbA==" title="https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.2.4/index.html">https://artifacts.elastic.co/javadoc/org/elasticsearch/client/elasticsearch-rest-high-level-client/6.2.4/index.html<i class="fa fa-external-link"></i></span></p>
<h2 id="9-1-REST-低级-Api"><a href="#9-1-REST-低级-Api" class="headerlink" title="9.1 REST 低级 Api"></a>9.1 REST 低级 Api</h2><p>低级客户端的功能包括：</p>
<ul>
<li>最小依赖</li>
<li>跨所有可用节点进行负载平衡</li>
<li>发生节点故障并根据特定响应代码进行故障转移</li>
<li>失败的连接惩罚（是否重试失败的节点取决于失败的连续次数；失败尝试次数越多，客户端在再次尝试该相同节点之前将等待的时间越长）</li>
<li>持续的联系</li>
<li>跟踪记录请求和响应</li>
<li>可选的自动<span class="exturl" data-url="aHR0cHM6Ly93d3cuZWxhc3RpYy5jby9ndWlkZS9lbi9lbGFzdGljc2VhcmNoL2NsaWVudC9qYXZhLXJlc3QvNi4yL3NuaWZmZXIuaHRtbA==" title="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.2/sniffer.html">发现群集节点<i class="fa fa-external-link"></i></span></li>
</ul>
<h3 id="9-1-1-起步"><a href="#9-1-1-起步" class="headerlink" title="9.1.1 起步"></a>9.1.1 起步</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;org.elasticsearch.client&lt;&#x2F;groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;elasticsearch-rest-client&lt;&#x2F;artifactId&gt;</span><br><span class="line">    &lt;version&gt;6.2.4&lt;&#x2F;version&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br></pre></td></tr></table></figure>

<h3 id="9-1-2-初始化"><a href="#9-1-2-初始化" class="headerlink" title="9.1.2 初始化"></a>9.1.2 初始化</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">可以通过相应的RestClientBuilder类（通过RestClient＃builder（HttpHost ...）静态方法创建）来构建RestClient实例。 唯一必需的参数是客户端将与之通信的一个或多个主机，以HttpHost的实例形式提供，如下所示：</span><br><span class="line">public static void main(String[] args) &#123;</span><br><span class="line">        RestClientBuilder restClientBuilder &#x3D; RestClient.builder(</span><br><span class="line">                new HttpHost(&quot;192.168.92.180&quot;, 9200, &quot;http&quot;));</span><br><span class="line">        &#x2F;&#x2F; 设置最大超时时间</span><br><span class="line">        restClientBuilder.setMaxRetryTimeoutMillis(10000);</span><br><span class="line">        &#x2F;&#x2F; 监听失效</span><br><span class="line">        restClientBuilder.setFailureListener(new RestClient.FailureListener() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void onFailure(HttpHost host) &#123;</span><br><span class="line">                System.err.println(&quot;连接失效&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        &#x2F;&#x2F; 设置连接的回调内容</span><br><span class="line">        restClientBuilder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) &#123;</span><br><span class="line">                System.err.println(&quot;sss&quot;);</span><br><span class="line">                System.err.println(&quot;sss&quot;);</span><br><span class="line">                System.err.println(&quot;sssf&quot;);</span><br><span class="line">                &#x2F;&#x2F; socket套接字连接超时时间</span><br><span class="line">                return builder.setSocketTimeout(10000);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        &#x2F;&#x2F; 设置回调的代理客户端</span><br><span class="line">        restClientBuilder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) &#123;</span><br><span class="line">                return httpClientBuilder.setProxy(new HttpHost(&quot;proxy&quot;, 9000, &quot;http&quot;));</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">        RestClient restClient &#x3D; restClientBuilder.build();</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>RestClient 是线程安全的</li>
<li>可以再建造器里面设置连接最大超时时间，默认为30秒</li>
<li>可以设置代理客户端</li>
<li>可以设置socket套接字超时时间</li>
</ul>
<h3 id="9-1-3-执行请求"><a href="#9-1-3-执行请求" class="headerlink" title="9.1.3 执行请求"></a>9.1.3 执行请求</h3><p>一旦<code>RestClient</code>被创建，请求可以通过调用可用的一个被发送<code>performRequest</code>或<code>performRequestAsync</code>方法的变体。这些<code>performRequest</code>方法是同步的，并且<code>Response</code>直接返回，这意味着客户端将阻塞并等待返回响应。该<code>performRequestAsync</code>变种返回<code>void</code>并接受额外的 <code>ResponseListener</code>作为参数来代替，这意味着它们是异步执行的。请求完成或失败时，将通知提供的侦听器。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">        RestClientBuilder restClientBuilder &#x3D; RestClient.builder(</span><br><span class="line">                new HttpHost(&quot;192.168.92.180&quot;, 9200, &quot;http&quot;));</span><br><span class="line">        RestClient restClient &#x3D; restClientBuilder.build();</span><br><span class="line">        &#x2F;&#x2F; 1. 发送一个普通的get请求</span><br><span class="line">&#x2F;&#x2F;        Map&lt;String, String&gt; params &#x3D; Collections.singletonMap(&quot;pretty&quot;, &quot;true&quot;);</span><br><span class="line">&#x2F;&#x2F;        Response response &#x3D; restClient.performRequest(&quot;GET&quot;, &quot;&#x2F;&quot;, params);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 2. 发送一个带参数的请求，并创建一个文档</span><br><span class="line">        Map&lt;Object, Object&gt; singletonMap &#x3D; Collections.emptyMap();</span><br><span class="line">        &#x2F;&#x2F; 请求url参数</span><br><span class="line">        Map&lt;String, String&gt; params &#x3D; Collections.singletonMap(&quot;pretty&quot;, &quot;true&quot;);</span><br><span class="line">        String jsonString &#x3D; &quot;&#123;&quot; +</span><br><span class="line">                &quot;\&quot;user\&quot;:\&quot;kimchy\&quot;,&quot; +</span><br><span class="line">                &quot;\&quot;postDate\&quot;:\&quot;2013-01-30\&quot;,&quot; +</span><br><span class="line">                &quot;\&quot;message\&quot;:\&quot;trying out Elasticsearch\&quot;&quot; +</span><br><span class="line">                &quot;&#125;&quot;;</span><br><span class="line">        &#x2F;&#x2F; 构建http请求体</span><br><span class="line">        HttpEntity entity &#x3D; new NStringEntity(jsonString, ContentType.APPLICATION_JSON);</span><br><span class="line">        &#x2F;&#x2F; 创建一个文档</span><br><span class="line">&#x2F;&#x2F;        Response response &#x3D; restClient.performRequest(&quot;PUT&quot;, &quot;&#x2F;posts&#x2F;doc&#x2F;1&quot;, params, entity);</span><br><span class="line">        &#x2F;&#x2F; 3. 创建一个_search 请求， 并且指定缓冲区的大小</span><br><span class="line">        HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory heapBufferedResponseConsumerFactory</span><br><span class="line">                &#x3D; new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(30 * 1024 * 1024);</span><br><span class="line">        &#x2F;&#x2F; 创建一个响应监听器</span><br><span class="line">        ResponseListener responseListener &#x3D; new ResponseListener() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void onSuccess(Response response) &#123;</span><br><span class="line">                System.err.println(&quot;响应成功&quot;);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            @Override</span><br><span class="line">            public void onFailure(Exception e) &#123;</span><br><span class="line">                System.err.println(&quot;响应失败&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">        restClient.performRequestAsync(&quot;GET&quot;, &quot;&#x2F;posts&#x2F;_search&quot;, params, null, heapBufferedResponseConsumerFactory, responseListener);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：为HttpEntity指定的ContentType很重要，因为它将用于设置Content-Type标头，以便Elasticsearch可以正确解析内容。</p>
</blockquote>
<h3 id="9-1-4-接受响应体的处理"><a href="#9-1-4-接受响应体的处理" class="headerlink" title="9.1.4 接受响应体的处理"></a>9.1.4 接受响应体的处理</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Response response &#x3D; restClient.performRequest(&quot;PUT&quot;, &quot;&#x2F;posts&#x2F;doc&#x2F;1&quot;, params, entity);</span><br><span class="line">RequestLine requestLine &#x3D; response.getRequestLine();</span><br><span class="line">HttpHost host &#x3D; response.getHost();</span><br><span class="line">int statusCode &#x3D; response.getStatusLine().getStatusCode();</span><br><span class="line">Header[] headers &#x3D; response.getHeaders();</span><br><span class="line">String responseBody &#x3D; EntityUtils.toString(response.getEntity());</span><br><span class="line"></span><br><span class="line">System.err.println(requestLine.getUri());</span><br><span class="line">System.err.println(responseBody);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>对于返回404状态代码的HEAD请求，不会引发ResponseException，因为这是预期的HEAD响应，它仅表示未找到资源。 除非ignore参数包含404，否则所有其他HTTP方法（例如GET）都将引发404响应的ResponseException。ignore是一个特殊的客户端参数，不会发送到Elasticsearch，并且包含逗号分隔的错误状态代码列表。 它允许控制是否将某些错误状态代码视为预期的响应而不是异常。 例如，这对于使用get api很有用，因为当缺少文档时它可以返回404，在这种情况下，响应主体将不包含错误，而是通常的get api响应，只是没有找到未找到的文档。</p>
</blockquote>
<h2 id="9-2-REST-高级-API"><a href="#9-2-REST-高级-API" class="headerlink" title="9.2 REST 高级 API"></a>9.2 REST 高级 API</h2><h3 id="9-2-1-机器翻译介绍"><a href="#9-2-1-机器翻译介绍" class="headerlink" title="9.2.1 机器翻译介绍"></a>9.2.1 机器翻译介绍</h3><p>Java高级REST客户端在Java高级REST客户端之上工作。它的主要目的是公开API特定的方法，这些方法接受请求对象作为参数并返回响应对象，以便请求编组和响应解编组由客户端本身处理。</p>
<p>每个API可以同步或异步调用。同步方法返回一个响应对象，而名称以<code>async</code>后缀结尾的异步方法则需要一个侦听器参数，一旦收到响应或错误，该参数将被通知（在低级客户端管理的线程池上）。</p>
<p>Java高级REST客户端取决于Elasticsearch核心项目。它接受与相同的请求参数，<code>TransportClient</code>并返回相同的响应对象。</p>
<h3 id="9-2-2-兼容性"><a href="#9-2-2-兼容性" class="headerlink" title="9.2.2 兼容性"></a>9.2.2 <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2VsYXN0aWMvZWxhc3RpY3NlYXJjaC9lZGl0LzYuMi9kb2NzL2phdmEtcmVzdC9oaWdoLWxldmVsL2dldHRpbmctc3RhcnRlZC5hc2NpaWRvYw==" title="https://github.com/elastic/elasticsearch/edit/6.2/docs/java-rest/high-level/getting-started.asciidoc">兼容性<i class="fa fa-external-link"></i></span></h3><p>Java高级REST客户端需要Java 1.8，并依赖于Elasticsearch核心项目。客户端版本与为其开发客户端的Elasticsearch版本相同。它接受与相同的请求参数，<code>TransportClient</code> 并返回相同的响应对象。 如果需要将应用程序从其迁移到新的REST客户端，请参阅《<a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.2/java-rest-high-level-migration.html" target="_blank" rel="noopener"><em>迁移指南》</em></a><code>TransportClient</code>。</p>
<p>确保高级客户端能够与在相同主要版本和较大或相等的次要版本上运行的任何Elasticsearch节点进行通信。它不需要与与其通信的Elasticsearch节点处于相同的次要版本，因为它是前向兼容的，这意味着它支持与比其开发的版本更高的Elasticsearch通信。</p>
<p>6.0客户端可以与任何6.x Elasticsearch节点进行通信，而6.1客户端可以与6.1、6.2和任何更高版本的6.x版本进行通信，但是与先前的Elasticsearch节点进行通信时可能会出现不兼容问题如果6.1客户端支持6.0节点不知道的某些API的新请求正文字段，则版本介于6.1和6.0之间。</p>
<p>建议将Elasticsearch群集升级到新的主要版本时升级High Level Client，因为REST API的重大更改可能会导致意外结果，具体取决于请求所命中的节点，并且新添加的API仅受支持。客户端的较新版本。一旦集群中的所有节点都已升级到新的主要版本，客户端应始终最后更新。</p>
<h3 id="9-2-3-起步"><a href="#9-2-3-起步" class="headerlink" title="9.2.3 起步"></a>9.2.3 起步</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;org.elasticsearch.client&lt;&#x2F;groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;elasticsearch-rest-high-level-client&lt;&#x2F;artifactId&gt;</span><br><span class="line">    &lt;version&gt;6.2.4&lt;&#x2F;version&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>org.elasticsearch.client:elasticsearch-rest-client</li>
<li>org.elasticsearch:elasticsearch</li>
</ul>
<h3 id="9-2-4-创建一个rest-连接"><a href="#9-2-4-创建一个rest-连接" class="headerlink" title="9.2.4 创建一个rest 连接"></a>9.2.4 创建一个rest 连接</h3><h3 id="9-2-5-【6-2-4】版本-支持的相关API-（重点）"><a href="#9-2-5-【6-2-4】版本-支持的相关API-（重点）" class="headerlink" title="9.2.5 【6.2.4】版本 支持的相关API （重点）"></a>9.2.5 【6.2.4】版本 支持的相关API （重点）</h3><h4 id="创建索引"><a href="#创建索引" class="headerlink" title="创建索引"></a>创建索引</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line">     * 创建索引</span><br><span class="line">     *&#x2F;</span><br><span class="line">    private static void createIndex(RestHighLevelClient client) throws Exception &#123;</span><br><span class="line">        &#x2F;&#x2F; 1. 创建索引请求，并且指定索引名称</span><br><span class="line">        CreateIndexRequest indexRequest &#x3D; new CreateIndexRequest(&quot;twitter&quot;);</span><br><span class="line">        &#x2F;&#x2F; 2. 设置索引的 settings 注意和es原生方式不同需要加index.</span><br><span class="line">        indexRequest.settings(Settings.builder()</span><br><span class="line">            .put(&quot;index.number_of_shards&quot;, 3)</span><br><span class="line">            .put(&quot;index.number_of_shards&quot;, 2));</span><br><span class="line">        &#x2F;&#x2F; 3. 设置mappings 映射。由于5.0升级需要加上 header请求类型</span><br><span class="line">        indexRequest.mapping(&quot;tweet&quot;,</span><br><span class="line">                &quot;  &#123;\n&quot; +</span><br><span class="line">                        &quot;    \&quot;tweet\&quot;: &#123;\n&quot; +</span><br><span class="line">                        &quot;      \&quot;properties\&quot;: &#123;\n&quot; +</span><br><span class="line">                        &quot;        \&quot;message\&quot;: &#123;\n&quot; +</span><br><span class="line">                        &quot;          \&quot;type\&quot;: \&quot;text\&quot;\n&quot; +</span><br><span class="line">                        &quot;        &#125;\n&quot; +</span><br><span class="line">                        &quot;      &#125;\n&quot; +</span><br><span class="line">                        &quot;    &#125;\n&quot; +</span><br><span class="line">                        &quot;  &#125;&quot;,</span><br><span class="line">                XContentType.JSON);</span><br><span class="line">        &#x2F;&#x2F; 4. 指定索引的别名</span><br><span class="line">        indexRequest.alias(</span><br><span class="line">                new Alias(&quot;twitter_alias&quot;)</span><br><span class="line">        );</span><br><span class="line">        &#x2F;&#x2F; 5. 可选参数提供</span><br><span class="line">        &#x2F;&#x2F; TODO: 这两个参数作用目前不太明确</span><br><span class="line">        indexRequest.timeout(TimeValue.timeValueMinutes(2));</span><br><span class="line">        indexRequest.timeout(&quot;2m&quot;);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 5.1连接到主节点的超时时间</span><br><span class="line">        indexRequest.masterNodeTimeout(TimeValue.timeValueMinutes(1));</span><br><span class="line">        indexRequest.masterNodeTimeout(&quot;1m&quot;);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 5.2 在创建索引API返回响应之前，要等待的活动碎片副本数</span><br><span class="line">        indexRequest.waitForActiveShards(2);</span><br><span class="line">        indexRequest.waitForActiveShards(ActiveShardCount.DEFAULT);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 6. 同步执行的方式</span><br><span class="line">        CreateIndexResponse createIndexResponse &#x3D; client.indices().create(indexRequest);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 7. 异步执行方式</span><br><span class="line">        &#x2F;&#x2F; 由于异步方式不能立刻返回结果，所以需要监听器去监听异步请求结果</span><br><span class="line">&#x2F;&#x2F;        ActionListener&lt;CreateIndexResponse&gt; listener &#x3D; new ActionListener&lt;CreateIndexResponse&gt;() &#123;</span><br><span class="line">&#x2F;&#x2F;            @Override</span><br><span class="line">&#x2F;&#x2F;            public void onResponse(CreateIndexResponse createIndexResponse) &#123;</span><br><span class="line">&#x2F;&#x2F;                System.err.println(&quot;返回结果&quot;);</span><br><span class="line">&#x2F;&#x2F;            &#125;</span><br><span class="line">&#x2F;&#x2F;</span><br><span class="line">&#x2F;&#x2F;            @Override</span><br><span class="line">&#x2F;&#x2F;            public void onFailure(Exception e) &#123;</span><br><span class="line">&#x2F;&#x2F;                System.err.println(&quot;出现异常&quot;);</span><br><span class="line">&#x2F;&#x2F;</span><br><span class="line">&#x2F;&#x2F;            &#125;</span><br><span class="line">&#x2F;&#x2F;        &#125;;</span><br><span class="line">&#x2F;&#x2F;        client.indices().createAsync(indexRequest, listener);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 8. 处理返回结果</span><br><span class="line">        boolean acknowledged &#x3D; createIndexResponse.isAcknowledged();</span><br><span class="line">        boolean shardsAcknowledged &#x3D; createIndexResponse.isShardsAcknowledged();</span><br><span class="line"></span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h4 id="删除索引"><a href="#删除索引" class="headerlink" title="删除索引"></a>删除索引</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line">     * 删除索引</span><br><span class="line">     * @param client</span><br><span class="line">     * @throws Exception</span><br><span class="line">     *&#x2F;</span><br><span class="line">    private static void deleteIndex(RestHighLevelClient client) throws Exception &#123;</span><br><span class="line">        &#x2F;&#x2F; 创建删除索引的对象</span><br><span class="line">        DeleteIndexRequest deleteIndexRequest &#x3D; new DeleteIndexRequest(&quot;twitter&quot;);</span><br><span class="line">        &#x2F;&#x2F; 2. TODO: 这两个参数作用目前不太明确</span><br><span class="line">        deleteIndexRequest.timeout(TimeValue.timeValueMinutes(2));</span><br><span class="line">        deleteIndexRequest.timeout(&quot;2m&quot;);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 2.1 连接到主节点的超时时间</span><br><span class="line">        deleteIndexRequest.masterNodeTimeout(TimeValue.timeValueMinutes(1));</span><br><span class="line">        deleteIndexRequest.masterNodeTimeout(&quot;1m&quot;);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 3. 设置IndicesOptions可以控制如何解决不可用的索引以及如何扩展通配符表达式</span><br><span class="line">        &#x2F;&#x2F; 3.1 IndicesOptions.lenientExpandOpen()</span><br><span class="line">        &#x2F;&#x2F; 索引选项将忽略不可用的索引，仅将通配符扩展为打开的索引，并不允许通配符表达式解析任何索引（不返回错误）</span><br><span class="line">        deleteIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 4.1 同步方式</span><br><span class="line">        DeleteIndexResponse delete &#x3D; client.indices().delete(deleteIndexRequest);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 4.2 异步方式</span><br><span class="line">&#x2F;&#x2F;        client.indices().deleteAsync(deleteIndexRequest, new ActionListener&lt;DeleteIndexResponse&gt;()&#123;</span><br><span class="line">&#x2F;&#x2F;</span><br><span class="line">&#x2F;&#x2F;            @Override</span><br><span class="line">&#x2F;&#x2F;            public void onResponse(DeleteIndexResponse deleteIndexResponse) &#123;</span><br><span class="line">&#x2F;&#x2F;                System.err.println(&quot;返回结果&quot;);</span><br><span class="line">&#x2F;&#x2F;            &#125;</span><br><span class="line">&#x2F;&#x2F;</span><br><span class="line">&#x2F;&#x2F;            @Override</span><br><span class="line">&#x2F;&#x2F;            public void onFailure(Exception e) &#123;</span><br><span class="line">&#x2F;&#x2F;                System.err.println(&quot;出现异常&quot;);</span><br><span class="line">&#x2F;&#x2F;            &#125;</span><br><span class="line">&#x2F;&#x2F;        &#125;);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 5. 如果删除的时候没有索引会发生什么？</span><br><span class="line">        &#x2F;&#x2F; 请根据如下代码进行处理</span><br><span class="line">&#x2F;&#x2F;        try &#123;</span><br><span class="line">&#x2F;&#x2F;            DeleteIndexRequest request &#x3D; new DeleteIndexRequest(&quot;does_not_exist&quot;);</span><br><span class="line">&#x2F;&#x2F;            client.indices().delete(request);</span><br><span class="line">&#x2F;&#x2F;        &#125; catch (ElasticsearchException exception) &#123;</span><br><span class="line">&#x2F;&#x2F;            if (exception.status() &#x3D;&#x3D; RestStatus.NOT_FOUND) &#123;</span><br><span class="line">&#x2F;&#x2F;              &#x2F;&#x2F;处理异常</span><br><span class="line">&#x2F;&#x2F;            &#125;</span><br><span class="line">&#x2F;&#x2F;        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h4 id="开放索引"><a href="#开放索引" class="headerlink" title="开放索引"></a>开放索引</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line">     * 开放索引</span><br><span class="line">     * @param client</span><br><span class="line">     *&#x2F;</span><br><span class="line">    public static void openIndex(RestHighLevelClient client) throws Exception&#123;</span><br><span class="line">        &#x2F;&#x2F; 1. 创建一个开放索引的请求</span><br><span class="line">        OpenIndexRequest openIndexRequest &#x3D; new OpenIndexRequest(&quot;myindex&quot;);</span><br><span class="line">        &#x2F;&#x2F; 2. 等待所有节点确认索引的超时被打开</span><br><span class="line">        openIndexRequest.timeout(TimeValue.timeValueMinutes(2));</span><br><span class="line">        &#x2F;&#x2F; 3. 设置请求开放索引处理策略</span><br><span class="line">        &#x2F;&#x2F; 要求每个指定索引都存在的索引选项，仅将通配符扩展为打开的索引，并且不允许通配符表达式解析任何索引（不返回错误）。</span><br><span class="line">        openIndexRequest.indicesOptions(IndicesOptions.strictExpandOpen());</span><br><span class="line">        &#x2F;&#x2F; 4. 设置开放索引API返回响应之前要等待的活动分片副本数</span><br><span class="line">        openIndexRequest.waitForActiveShards(2);</span><br><span class="line">        &#x2F;&#x2F; 4.1 ActiveShardCount 存在多个选下那个</span><br><span class="line">        openIndexRequest.waitForActiveShards(ActiveShardCount.ONE);</span><br><span class="line">        &#x2F;&#x2F; 5. 同步方式</span><br><span class="line">        OpenIndexResponse openIndexResponse &#x3D; client.indices().open(openIndexRequest);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 6. 异步方式</span><br><span class="line">        &#x2F;&#x2F; 由于异步方式不能立刻返回结果，所以需要监听器去监听异步请求结果</span><br><span class="line">&#x2F;&#x2F;        ActionListener&lt;OpenIndexResponse&gt; listener &#x3D; new ActionListener&lt;OpenIndexResponse&gt;() &#123;</span><br><span class="line">&#x2F;&#x2F;            @Override</span><br><span class="line">&#x2F;&#x2F;            public void onResponse(CreateIndexResponse createIndexResponse) &#123;</span><br><span class="line">&#x2F;&#x2F;                System.err.println(&quot;返回结果&quot;);</span><br><span class="line">&#x2F;&#x2F;            &#125;</span><br><span class="line">&#x2F;&#x2F;</span><br><span class="line">&#x2F;&#x2F;            @Override</span><br><span class="line">&#x2F;&#x2F;            public void onFailure(Exception e) &#123;</span><br><span class="line">&#x2F;&#x2F;                System.err.println(&quot;出现异常&quot;);</span><br><span class="line">&#x2F;&#x2F;</span><br><span class="line">&#x2F;&#x2F;            &#125;</span><br><span class="line">&#x2F;&#x2F;        &#125;;</span><br><span class="line">&#x2F;&#x2F;        client.indices().openAsync(openIndexRequest, listener);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 7. 分片是否正常响应</span><br><span class="line">        openIndexResponse.isShardsAcknowledged();</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h4 id="关闭索引"><a href="#关闭索引" class="headerlink" title="关闭索引"></a>关闭索引</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line">   * 关闭索引</span><br><span class="line">   * @param client</span><br><span class="line">   *&#x2F;</span><br><span class="line">  private static void closeIndex(RestHighLevelClient client) throws Exception&#123;</span><br><span class="line">      &#x2F;&#x2F; 1. 创建一个关闭索引的对象</span><br><span class="line">      CloseIndexRequest closeIndexRequest &#x3D; new CloseIndexRequest(&quot;myindex&quot;);</span><br><span class="line">      &#x2F;&#x2F; 2. 基本设置： 大同小异，不多啰嗦了</span><br><span class="line">      closeIndexRequest.timeout(TimeValue.timeValueMinutes(2));</span><br><span class="line">      closeIndexRequest.timeout(&quot;2m&quot;);</span><br><span class="line">      closeIndexRequest.masterNodeTimeout(TimeValue.timeValueMinutes(1));</span><br><span class="line">      closeIndexRequest.masterNodeTimeout(&quot;1m&quot;);</span><br><span class="line">      closeIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());</span><br><span class="line">      &#x2F;&#x2F; 3. 同步方式</span><br><span class="line">      CloseIndexResponse closeIndexResponse &#x3D; client.indices().close(closeIndexRequest);</span><br><span class="line">      &#x2F;&#x2F; 4. 异步方式</span><br><span class="line">      client.indices().closeAsync(closeIndexRequest, new ActionListener&lt;CloseIndexResponse&gt;() &#123;</span><br><span class="line">          @Override</span><br><span class="line">          public void onResponse(CloseIndexResponse closeIndexResponse) &#123;</span><br><span class="line">              &#x2F;&#x2F; ....</span><br><span class="line">          &#125;</span><br><span class="line"></span><br><span class="line">          @Override</span><br><span class="line">          public void onFailure(Exception e) &#123;</span><br><span class="line">              &#x2F;&#x2F; ....</span><br><span class="line">          &#125;</span><br><span class="line">      &#125;);</span><br><span class="line"></span><br><span class="line">      boolean acknowledged &#x3D; closeIndexResponse.isAcknowledged();</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<h3 id="9-2-6-索引本身的API"><a href="#9-2-6-索引本身的API" class="headerlink" title="9.2.6 索引本身的API"></a>9.2.6 索引本身的API</h3><h4 id="直接根据索引创建一个文档需要如下参数"><a href="#直接根据索引创建一个文档需要如下参数" class="headerlink" title="直接根据索引创建一个文档需要如下参数"></a>直接根据索引创建一个文档需要如下参数</h4><ol>
<li>索引名称</li>
<li>索引类型</li>
<li>文档id</li>
<li>文档数据：提供一个json数据</li>
</ol>
<h4 id="提供文档来源的多种方式"><a href="#提供文档来源的多种方式" class="headerlink" title="提供文档来源的多种方式"></a>提供文档来源的多种方式</h4><p>可以使用不同的方式来创建文档源数据</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">Map&lt;String, Object&gt; jsonMap &#x3D; new HashMap&lt;&gt;();</span><br><span class="line">jsonMap.put(&quot;user&quot;, &quot;kimchy&quot;);</span><br><span class="line">jsonMap.put(&quot;postData&quot;, new Date());</span><br><span class="line">jsonMap.put(&quot;message&quot;, &quot;trying out Elasticsearch&quot;);</span><br><span class="line">&#x2F;&#x2F; 5. 使用map创建</span><br><span class="line">indexRequest.source(indexRequest, jsonMap);</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 6. es 官方开发了 XContentBuilder 来构建_source 的请求json</span><br><span class="line">XContentBuilder xContentBuilder &#x3D; XContentFactory.jsonBuilder();</span><br><span class="line">xContentBuilder.startObject();</span><br><span class="line">&#123;</span><br><span class="line">    xContentBuilder.field(&quot;user&quot;, &quot;kimchy&quot;);</span><br><span class="line">    xContentBuilder.field(&quot;postDate&quot;, new Date());</span><br><span class="line">    xContentBuilder.field(&quot;message&quot;, &quot;trying out Elasticsearch&quot;);</span><br><span class="line">&#125;</span><br><span class="line">xContentBuilder.endObject();</span><br><span class="line">IndexRequest source &#x3D; indexRequest.source(xContentBuilder);</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 7. 也可以在_soucre 的时候直接传入键值对数据</span><br><span class="line">indexRequest.source(&quot;user&quot;, &quot;kimchy&quot;,</span><br><span class="line">                    &quot;postDate&quot;, new Date(),</span><br><span class="line">                    &quot;message&quot;, &quot;trying out Elasticsearch&quot;);</span><br></pre></td></tr></table></figure>

<h4 id="可选参数"><a href="#可选参数" class="headerlink" title="可选参数"></a>可选参数</h4><p>设置路由</p>
<p>设置parent 值</p>
<p>设置分片处理的超时时间</p>
<p>将策略刷新为WriteRequest.RefreshPolicy实例</p>
<p>设置初始版本号</p>
<p>设置版本类型?</p>
<p>提供类型形式修改操作类型，以及以字符串形式提供的操作类型：可以创建或更新（默认）</p>
<p>索引文档之前要执行的管道流的名称</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 8. 可选参数</span><br><span class="line">&#x2F;&#x2F; 8.1 设置路由</span><br><span class="line">indexRequest.routing(&quot;routing&quot;);</span><br><span class="line">&#x2F;&#x2F; 8.2 设置父索引</span><br><span class="line">indexRequest.parent(&quot;parent&quot;);</span><br><span class="line">&#x2F;&#x2F; 8.3 设置分片处理的超时时间</span><br><span class="line">indexRequest.timeout(TimeValue.timeValueSeconds(1));</span><br><span class="line">indexRequest.timeout(&quot;1s&quot;);</span><br><span class="line">&#x2F;&#x2F; 8.4 设置刷新策略</span><br><span class="line">indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);</span><br><span class="line">indexRequest.setRefreshPolicy(&quot;wait_for&quot;);</span><br><span class="line">&#x2F;&#x2F; 8.5 设置版本号</span><br><span class="line">indexRequest.version(2);</span><br><span class="line">&#x2F;&#x2F; 8.6 设置版本类型</span><br><span class="line">indexRequest.versionType(VersionType.EXTERNAL);</span><br><span class="line">&#x2F;&#x2F; 8.7 提供类型形式修改操作类型，以及以字符串形式提供的操作类型：可以创建或更新（默认）</span><br><span class="line">indexRequest.opType(DocWriteRequest.OpType.CREATE);</span><br><span class="line">indexRequest.opType(&quot;create&quot;);</span><br><span class="line">&#x2F;&#x2F; 8.8 索引文档之前要执行的管道流的名称</span><br><span class="line">indexRequest.setPipeline(&quot;pipeline&quot;);</span><br></pre></td></tr></table></figure>

<h4 id="获取响应内容"><a href="#获取响应内容" class="headerlink" title="获取响应内容"></a>获取响应内容</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 11. 处理响应体内容</span><br><span class="line">indexResponse.getIndex();</span><br><span class="line">indexResponse.getId();</span><br><span class="line">indexResponse.getType();</span><br><span class="line">indexResponse.getVersion();</span><br><span class="line">if (indexResponse.getResult() &#x3D;&#x3D; DocWriteResponse.Result.CREATED) &#123;</span><br><span class="line">    &#x2F;&#x2F; 如果是创建</span><br><span class="line"></span><br><span class="line">&#125; else if (indexResponse.getResult() &#x3D;&#x3D; DocWriteResponse.Result.UPDATED) &#123;</span><br><span class="line">    &#x2F;&#x2F; 如果是修改</span><br><span class="line">&#125;</span><br><span class="line">ReplicationResponse.ShardInfo shardInfo &#x3D; indexResponse.getShardInfo();</span><br><span class="line">if (shardInfo.getTotal() !&#x3D; shardInfo.getSuccessful()) &#123;</span><br><span class="line">    &#x2F;&#x2F; 如果存在失败分片（即返回部分信息）如何处理</span><br><span class="line">&#125;</span><br><span class="line">if (shardInfo.getFailed() &gt; 0) &#123;</span><br><span class="line">    for (ReplicationResponse.ShardInfo.Failure failure : shardInfo.getFailures()) &#123;</span><br><span class="line">        &#x2F;&#x2F; 获取失败原因</span><br><span class="line">        String reason &#x3D; failure.reason();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="根据上述内容整合"><a href="#根据上述内容整合" class="headerlink" title="根据上述内容整合"></a>根据上述内容整合</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line">     * 根据索引创建一个索引文档</span><br><span class="line">     * @param client</span><br><span class="line">     * @throws Exception</span><br><span class="line">     *&#x2F;</span><br><span class="line">    private static void createIndexDocumentByIndex(RestHighLevelClient client) throws Exception&#123;</span><br><span class="line">        &#x2F;&#x2F; 1. 创建 索引请求</span><br><span class="line">        IndexRequest indexRequest &#x3D; new IndexRequest(</span><br><span class="line">                &quot;posts&quot;,</span><br><span class="line">                &quot;doc&quot;,</span><br><span class="line">                &quot;1&quot;);</span><br><span class="line">        &#x2F;&#x2F; 2. _source 元数据</span><br><span class="line">        String jsonString &#x3D; &quot;&#123;&quot; +</span><br><span class="line">                &quot;\&quot;user\&quot;:\&quot;kimchy\&quot;,&quot; +</span><br><span class="line">                &quot;\&quot;postDate\&quot;:\&quot;2013-01-30\&quot;,&quot; +</span><br><span class="line">                &quot;\&quot;message\&quot;:\&quot;trying out Elasticsearch\&quot;&quot; +</span><br><span class="line">                &quot;&#125;&quot;;</span><br><span class="line">        &#x2F;&#x2F; 3. 设置元数据</span><br><span class="line">        indexRequest.source(indexRequest, jsonString);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 4. 提供另外一种方式</span><br><span class="line">        Map&lt;String, Object&gt; jsonMap &#x3D; new HashMap&lt;&gt;();</span><br><span class="line">        jsonMap.put(&quot;user&quot;, &quot;kimchy&quot;);</span><br><span class="line">        jsonMap.put(&quot;postData&quot;, new Date());</span><br><span class="line">        jsonMap.put(&quot;message&quot;, &quot;trying out Elasticsearch&quot;);</span><br><span class="line">        &#x2F;&#x2F; 5. 使用map创建</span><br><span class="line">        indexRequest.source(indexRequest, jsonMap);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 6. es 官方开发了 XContentBuilder 来构建_source 的请求json</span><br><span class="line">        XContentBuilder xContentBuilder &#x3D; XContentFactory.jsonBuilder();</span><br><span class="line">        xContentBuilder.startObject();</span><br><span class="line">        &#123;</span><br><span class="line">            xContentBuilder.field(&quot;user&quot;, &quot;kimchy&quot;);</span><br><span class="line">            xContentBuilder.field(&quot;postDate&quot;, new Date());</span><br><span class="line">            xContentBuilder.field(&quot;message&quot;, &quot;trying out Elasticsearch&quot;);</span><br><span class="line">        &#125;</span><br><span class="line">        xContentBuilder.endObject();</span><br><span class="line">        IndexRequest source &#x3D; indexRequest.source(xContentBuilder);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 7. 也可以在_soucre 的时候直接传入键值对数据</span><br><span class="line">        indexRequest.source(&quot;user&quot;, &quot;kimchy&quot;,</span><br><span class="line">                        &quot;postDate&quot;, new Date(),</span><br><span class="line">                        &quot;message&quot;, &quot;trying out Elasticsearch&quot;);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 8. 可选参数</span><br><span class="line">        &#x2F;&#x2F; 8.1 设置路由</span><br><span class="line">        indexRequest.routing(&quot;routing&quot;);</span><br><span class="line">        &#x2F;&#x2F; 8.2 设置父索引</span><br><span class="line">        indexRequest.parent(&quot;parent&quot;);</span><br><span class="line">        &#x2F;&#x2F; 8.3 设置分片处理的超时时间</span><br><span class="line">        indexRequest.timeout(TimeValue.timeValueSeconds(1));</span><br><span class="line">        indexRequest.timeout(&quot;1s&quot;);</span><br><span class="line">        &#x2F;&#x2F; 8.4 设置刷新策略</span><br><span class="line">        indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);</span><br><span class="line">        indexRequest.setRefreshPolicy(&quot;wait_for&quot;);</span><br><span class="line">        &#x2F;&#x2F; 8.5 设置版本号</span><br><span class="line">        indexRequest.version(2);</span><br><span class="line">        &#x2F;&#x2F; 8.6 设置版本类型</span><br><span class="line">        indexRequest.versionType(VersionType.EXTERNAL);</span><br><span class="line">        &#x2F;&#x2F; 8.7 提供类型形式修改操作类型，以及以字符串形式提供的操作类型：可以创建或更新（默认）</span><br><span class="line">        indexRequest.opType(DocWriteRequest.OpType.CREATE);</span><br><span class="line">        indexRequest.opType(&quot;create&quot;);</span><br><span class="line">        &#x2F;&#x2F; 8.8 索引文档之前要执行的管道流的名称</span><br><span class="line">        indexRequest.setPipeline(&quot;pipeline&quot;);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 9. 同步方式</span><br><span class="line">        IndexResponse indexResponse &#x3D; client.index(indexRequest);</span><br><span class="line">        &#x2F;&#x2F; 10. 异步方式</span><br><span class="line">        client.indexAsync(indexRequest, new ActionListener&lt;IndexResponse&gt;() &#123;</span><br><span class="line">            @Override</span><br><span class="line">            public void onResponse(IndexResponse indexResponse) &#123;</span><br><span class="line">                &#x2F;&#x2F; ...</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            @Override</span><br><span class="line">            public void onFailure(Exception e) &#123;</span><br><span class="line">                &#x2F;&#x2F; ....</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 11. 处理响应体内容</span><br><span class="line">        indexResponse.getIndex();</span><br><span class="line">        indexResponse.getId();</span><br><span class="line">        indexResponse.getType();</span><br><span class="line">        indexResponse.getVersion();</span><br><span class="line">        if (indexResponse.getResult() &#x3D;&#x3D; DocWriteResponse.Result.CREATED) &#123;</span><br><span class="line">            &#x2F;&#x2F; 如果是创建</span><br><span class="line"></span><br><span class="line">        &#125; else if (indexResponse.getResult() &#x3D;&#x3D; DocWriteResponse.Result.UPDATED) &#123;</span><br><span class="line">            &#x2F;&#x2F; 如果是修改</span><br><span class="line">        &#125;</span><br><span class="line">        ReplicationResponse.ShardInfo shardInfo &#x3D; indexResponse.getShardInfo();</span><br><span class="line">        if (shardInfo.getTotal() !&#x3D; shardInfo.getSuccessful()) &#123;</span><br><span class="line">            &#x2F;&#x2F; 如果存在失败分片（即返回部分信息）如何处理</span><br><span class="line">        &#125;</span><br><span class="line">        if (shardInfo.getFailed() &gt; 0) &#123;</span><br><span class="line">            for (ReplicationResponse.ShardInfo.Failure failure : shardInfo.getFailures()) &#123;</span><br><span class="line">                &#x2F;&#x2F; 获取失败原因</span><br><span class="line">                String reason &#x3D; failure.reason();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h1 id="10-Elasticsearch-JAVA-API-的学习使用"><a href="#10-Elasticsearch-JAVA-API-的学习使用" class="headerlink" title="10. Elasticsearch JAVA API 的学习使用"></a>10. Elasticsearch JAVA API 的学习使用</h1><h2 id="10-1-起步："><a href="#10-1-起步：" class="headerlink" title="10.1 起步："></a>10.1 起步：</h2><h3 id="10-1-1-Maven-依赖"><a href="#10-1-1-Maven-依赖" class="headerlink" title="10.1.1 Maven 依赖"></a>10.1.1 Maven 依赖</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;org.elasticsearch.client&lt;&#x2F;groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;transport&lt;&#x2F;artifactId&gt;</span><br><span class="line">    &lt;version&gt;6.2.4&lt;&#x2F;version&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br></pre></td></tr></table></figure>

<h1 id="11-Es-painless-脚本插件使用（Elasticsearch-script-plugin）"><a href="#11-Es-painless-脚本插件使用（Elasticsearch-script-plugin）" class="headerlink" title="11. Es painless 脚本插件使用（Elasticsearch script plugin）"></a>11. Es painless 脚本插件使用（Elasticsearch script plugin）</h1><p>如果需要使用原生java语言实现自定义评分，需要实现官方提供的一个scriptEngine接口，官方在git上面给出了一个案例</p>
<h2 id="11-1-前置条件：windows安装gradle"><a href="#11-1-前置条件：windows安装gradle" class="headerlink" title="11.1 前置条件：windows安装gradle"></a>11.1 前置条件：windows安装gradle</h2><p>官方推荐用gradle 来构建插件的Jar包，为了怕出现麻烦，直接按照官方给的要求来，这里先列出一下gradle的基本安装步骤</p>
<h3 id="11-1-1-官方下载地址"><a href="#11-1-1-官方下载地址" class="headerlink" title="11.1.1 官方下载地址"></a>11.1.1 官方下载地址</h3><p><span class="exturl" data-url="aHR0cHM6Ly9zZXJ2aWNlcy5ncmFkbGUub3JnL2Rpc3RyaWJ1dGlvbnMv" title="https://services.gradle.org/distributions/">https://services.gradle.org/distributions/<i class="fa fa-external-link"></i></span></p>
<p>下载 <strong>gradle-5.6.3-all.zip</strong> 包，注意别下错了</p>
<h3 id="11-1-2-将gradle放入合适位置，将gradle加入path环境变量"><a href="#11-1-2-将gradle放入合适位置，将gradle加入path环境变量" class="headerlink" title="11.1.2 将gradle放入合适位置，将gradle加入path环境变量"></a>11.1.2 将gradle放入合适位置，将gradle加入path环境变量</h3><h3 id="11-1-3-配置阿里云的镜像"><a href="#11-1-3-配置阿里云的镜像" class="headerlink" title="11.1.3 配置阿里云的镜像"></a>11.1.3 配置阿里云的镜像</h3><h1 id="N-kibana-学习es的所有内容"><a href="#N-kibana-学习es的所有内容" class="headerlink" title="N kibana 学习es的所有内容"></a>N kibana 学习es的所有内容</h1><h2 id="2019-10-14"><a href="#2019-10-14" class="headerlink" title="2019.10.14"></a>2019.10.14</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br></pre></td><td class="code"><pre><span class="line">GET _search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">PUT &#x2F;lib&#x2F;</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">  &quot;settings&quot;:&#123;</span><br><span class="line"></span><br><span class="line">  &quot;index&quot;:&#123;</span><br><span class="line">  </span><br><span class="line">    &quot;number_of_shards&quot;: 5,</span><br><span class="line">    </span><br><span class="line">    &quot;number_of_replicas&quot;: 1</span><br><span class="line">    </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">GET _all&#x2F;_settings</span><br><span class="line"></span><br><span class="line">POST &#x2F;lib&#x2F;user&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">    &quot;first_name&quot; :  &quot;wang&quot;,</span><br><span class="line">    &quot;last_name&quot; :   &quot;laji&quot;,</span><br><span class="line">    &quot;age&quot; :         333,</span><br><span class="line">    &quot;about&quot; :       &quot;I hide to collect rock albums&quot;,</span><br><span class="line">    &quot;interests&quot;:  [ &quot;basket&quot; ]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">GET &#x2F;+get-toge*,-get-together&#x2F;_search</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search?from&#x3D;2&amp;size&#x3D;2</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search?sort&#x3D;age:_id&amp;_source&#x3D;first_name,age</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search?q&#x3D;first_name:ne</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;size&quot;: 2,</span><br><span class="line">  &quot;from&quot;: 2</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;_source&quot;: [&quot;*_name&quot;, &quot;a*&quot;]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;_source&quot;: &#123;</span><br><span class="line">    &quot;includes&quot;: [&quot;*_name&quot;, &quot;age&quot;],</span><br><span class="line">    &quot;excludes&quot;: [&quot;first_name&quot;]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;sort&quot;: [</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;age&quot;: &#123;</span><br><span class="line">        &quot;order&quot;: &quot;desc&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line"> </span><br><span class="line">    &quot;_score&quot;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;from&quot;: 0,</span><br><span class="line">  &quot;size&quot;: 2,</span><br><span class="line">  &quot;_source&quot;: [&quot;*_name&quot;, &quot;age&quot;],</span><br><span class="line">  &quot;sort&quot;: [</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;age&quot;:&quot;desc&quot;  </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &quot;Jane&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  </span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;match&quot;: &#123;</span><br><span class="line">            &quot;about&quot;: &quot;hide&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ], </span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;wang&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search?q&#x3D;wang</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      &quot;default_field&quot;: &quot;first_name&quot;,</span><br><span class="line">      &quot;query&quot;: &quot;first_name:wang OR first_name:jane AND age:[0 TO  999]&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;_id&quot;: 1</span><br><span class="line">        &#125; </span><br><span class="line">        </span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;terms&quot;: &#123;</span><br><span class="line">      &quot;about&quot;: [</span><br><span class="line">        &quot;i&quot;,</span><br><span class="line">        &quot;hide&quot;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;Jane wang&quot;,</span><br><span class="line">        &quot;operator&quot;: &quot;or&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;type&quot;: &quot;phrase_prefix&quot;,</span><br><span class="line">        &quot;query&quot;: &quot;hide&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_phrase&quot;: &#123;</span><br><span class="line">      &quot;about&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;to rock&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_phrase_prefix&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;wa&quot;,</span><br><span class="line">        &quot;max_expansions&quot;: 5</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;multi_match&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;wang smith&quot;,</span><br><span class="line">        &quot;fields&quot;: [&quot;first_name&quot;, &quot;last_name&quot;]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;match_phrase&quot;:  &#123;</span><br><span class="line">            &quot;about&quot;: &#123;</span><br><span class="line">              &quot;query&quot;: &quot;i to&quot;,</span><br><span class="line">              &quot;slop&quot;: 1</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;should&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;term&quot;: &#123;</span><br><span class="line">            &quot;first_name&quot;: &#123;</span><br><span class="line">              &quot;value&quot;: &quot;wang&quot;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;must_not&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;query_string&quot;: &#123;</span><br><span class="line">            &quot;default_field&quot;: &quot;age&quot;,</span><br><span class="line">            &quot;query&quot;: &quot;first_name:jane&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;minimum_should_match&quot;: 1</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;myindex&#x2F;test&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">  &quot;age&quot;: 5,</span><br><span class="line">  &quot;birthday&quot;: &quot;2019-05-04&quot;,</span><br><span class="line">  &quot;test_field&quot;: &quot;zzzzzz&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;range&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;gte&quot;: &quot;li&quot;,</span><br><span class="line">        &quot;lte&quot;: &quot;o&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;prefix&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;value&quot;: &quot;Li&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;wildcard&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;value&quot;: &quot;lix?ao*&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;exists&quot;: &#123;</span><br><span class="line">          &quot;field&quot;: &quot;name&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;missing&quot;: &#123;</span><br><span class="line">          &quot;field&quot;: &quot;test_field&quot;,</span><br><span class="line">          &quot;existence&quot;: true,</span><br><span class="line">          &quot;null_value&quot;: true</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;query_string&quot;: &#123;</span><br><span class="line">            &quot;default_field&quot;: &quot;name&quot;,</span><br><span class="line">            &quot;query&quot;: &quot;che*&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">POST &#x2F;mymyindex&#x2F;</span><br></pre></td></tr></table></figure>

<h2 id="2019-10-15"><a href="#2019-10-15" class="headerlink" title="2019.10.15"></a>2019.10.15</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br></pre></td><td class="code"><pre><span class="line">GET _search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">PUT &#x2F;lib&#x2F;</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">  &quot;settings&quot;:&#123;</span><br><span class="line"></span><br><span class="line">  &quot;index&quot;:&#123;</span><br><span class="line">  </span><br><span class="line">    &quot;number_of_shards&quot;: 5,</span><br><span class="line">    </span><br><span class="line">    &quot;number_of_replicas&quot;: 1</span><br><span class="line">    </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">GET _all&#x2F;_settings</span><br><span class="line"></span><br><span class="line">POST &#x2F;lib&#x2F;user&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">    &quot;first_name&quot; :  &quot;wang&quot;,</span><br><span class="line">    &quot;last_name&quot; :   &quot;laji&quot;,</span><br><span class="line">    &quot;age&quot; :         333,</span><br><span class="line">    &quot;about&quot; :       &quot;I hide to collect rock albums&quot;,</span><br><span class="line">    &quot;interests&quot;:  [ &quot;basket&quot; ]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">GET &#x2F;+get-toge*,-get-together&#x2F;_search</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search?from&#x3D;2&amp;size&#x3D;2</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search?sort&#x3D;age:_id&amp;_source&#x3D;first_name,age</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search?q&#x3D;first_name:ne</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;size&quot;: 2,</span><br><span class="line">  &quot;from&quot;: 2</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;_source&quot;: [&quot;*_name&quot;, &quot;a*&quot;]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;_source&quot;: &#123;</span><br><span class="line">    &quot;includes&quot;: [&quot;*_name&quot;, &quot;age&quot;],</span><br><span class="line">    &quot;excludes&quot;: [&quot;first_name&quot;]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;sort&quot;: [</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;age&quot;: &#123;</span><br><span class="line">        &quot;order&quot;: &quot;desc&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line"> </span><br><span class="line">    &quot;_score&quot;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;from&quot;: 0,</span><br><span class="line">  &quot;size&quot;: 2,</span><br><span class="line">  &quot;_source&quot;: [&quot;*_name&quot;, &quot;age&quot;],</span><br><span class="line">  &quot;sort&quot;: [</span><br><span class="line">    &#123;</span><br><span class="line">      &quot;age&quot;:&quot;desc&quot;  </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &quot;Jane&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  </span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;match&quot;: &#123;</span><br><span class="line">            &quot;about&quot;: &quot;hide&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ], </span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;first_name&quot;: &quot;wang&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search?q&#x3D;wang</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      &quot;default_field&quot;: &quot;first_name&quot;,</span><br><span class="line">      &quot;query&quot;: &quot;first_name:wang OR first_name:jane AND age:[0 TO  999]&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;term&quot;: &#123;</span><br><span class="line">          &quot;_id&quot;: 1</span><br><span class="line">        &#125; </span><br><span class="line">        </span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;terms&quot;: &#123;</span><br><span class="line">      &quot;about&quot;: [</span><br><span class="line">        &quot;i&quot;,</span><br><span class="line">        &quot;hide&quot;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;Jane wang&quot;,</span><br><span class="line">        &quot;operator&quot;: &quot;or&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;type&quot;: &quot;phrase_prefix&quot;,</span><br><span class="line">        &quot;query&quot;: &quot;hide&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_phrase&quot;: &#123;</span><br><span class="line">      &quot;about&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;to rock&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_phrase_prefix&quot;: &#123;</span><br><span class="line">      &quot;first_name&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;wa&quot;,</span><br><span class="line">        &quot;max_expansions&quot;: 5</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;lib&#x2F;user&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;multi_match&quot;: &#123;</span><br><span class="line">        &quot;query&quot;: &quot;wang smith&quot;,</span><br><span class="line">        &quot;fields&quot;: [&quot;first_name&quot;, &quot;last_name&quot;]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;lib&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;match_phrase&quot;:  &#123;</span><br><span class="line">            &quot;about&quot;: &#123;</span><br><span class="line">              &quot;query&quot;: &quot;i to&quot;,</span><br><span class="line">              &quot;slop&quot;: 1</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;should&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;term&quot;: &#123;</span><br><span class="line">            &quot;first_name&quot;: &#123;</span><br><span class="line">              &quot;value&quot;: &quot;wang&quot;</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;must_not&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;query_string&quot;: &#123;</span><br><span class="line">            &quot;default_field&quot;: &quot;age&quot;,</span><br><span class="line">            &quot;query&quot;: &quot;first_name:jane&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ],</span><br><span class="line">      &quot;minimum_should_match&quot;: 1</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;myindex&#x2F;test&#x2F;</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;: &quot;lixiaolong&quot;,</span><br><span class="line">  &quot;age&quot;: 5,</span><br><span class="line">  &quot;birthday&quot;: &quot;2019-05-04&quot;,</span><br><span class="line">  &quot;test_field&quot;: &quot;zzzzzz&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;range&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;gte&quot;: &quot;li&quot;,</span><br><span class="line">        &quot;lte&quot;: &quot;o&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;prefix&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;value&quot;: &quot;Li&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;wildcard&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;value&quot;: &quot;lix?ao*&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;test&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;exists&quot;: &#123;</span><br><span class="line">          &quot;field&quot;: &quot;name&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;missing&quot;: &#123;</span><br><span class="line">          &quot;field&quot;: &quot;test_field&quot;,</span><br><span class="line">          &quot;existence&quot;: true,</span><br><span class="line">          &quot;null_value&quot;: true</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;myindex&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;bool&quot;: &#123;</span><br><span class="line">      &quot;must&quot;: [</span><br><span class="line">        &#123;</span><br><span class="line">          &quot;query_string&quot;: &#123;</span><br><span class="line">            &quot;default_field&quot;: &quot;name&quot;,</span><br><span class="line">            &quot;query&quot;: &quot;che*&quot;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">DELETE &#x2F;mymyindex&#x2F; </span><br><span class="line"></span><br><span class="line">PUT &#x2F;mymyindex</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;: &#123;</span><br><span class="line">    &quot;analysis&quot;: &#123;</span><br><span class="line">      &quot;analyzer&quot;: &#123;</span><br><span class="line">        &quot;std_folded&quot;: &#123; </span><br><span class="line">          &quot;type&quot;: &quot;custom&quot;,</span><br><span class="line">          &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">          &quot;filter&quot;: [</span><br><span class="line">            &quot;lowercase&quot;,</span><br><span class="line">            &quot;asciifolding&quot;</span><br><span class="line">          ]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  &quot;mappings&quot;: &#123;</span><br><span class="line">    &quot;_doc&quot;: &#123;</span><br><span class="line">      &quot;properties&quot;: &#123;</span><br><span class="line">        &quot;my_text&quot;: &#123;</span><br><span class="line">          &quot;type&quot;: &quot;text&quot;,</span><br><span class="line">          &quot;analyzer&quot;: &quot;std_folded&quot; </span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;mymyindex&#x2F;_mapping</span><br><span class="line"></span><br><span class="line">POST &#x2F;mymyindex&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;whitespace&quot;, </span><br><span class="line">  &quot;filter&quot;: [</span><br><span class="line">    &quot;reverse&quot;</span><br><span class="line">  ],</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog\u0027s bone.&quot;,</span><br><span class="line">  &quot;field&quot;: &quot;my_text&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;get-together&#x2F;group&#x2F;3q8nz20BXNiyabSjyH-c&#x2F;_termvectors</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">PUT &#x2F;my_index</span><br><span class="line">&#123;</span><br><span class="line">    &quot;settings&quot;: &#123;</span><br><span class="line">        &quot;analysis&quot;: &#123;</span><br><span class="line">            &quot;char_filter&quot;: &#123;</span><br><span class="line">                &quot;&amp;_to_and&quot;: &#123;</span><br><span class="line">                    &quot;type&quot;:       &quot;mapping&quot;,</span><br><span class="line">                    &quot;mappings&quot;: [ &quot;&amp; &#x3D;&gt; and &quot;]</span><br><span class="line">            &#125;&#125;,</span><br><span class="line">            &quot;filter&quot;: &#123;</span><br><span class="line">                &quot;my_stopwords&quot;: &#123;</span><br><span class="line">                    &quot;type&quot;:       &quot;stop&quot;,</span><br><span class="line">                    &quot;stopwords&quot;: [ &quot;the&quot;, &quot;a&quot; ]</span><br><span class="line">            &#125;&#125;,</span><br><span class="line">            &quot;analyzer&quot;: &#123;</span><br><span class="line">                &quot;my_analyzer&quot;: &#123;</span><br><span class="line">                    &quot;type&quot;:         &quot;custom&quot;,</span><br><span class="line">                    &quot;char_filter&quot;:  [ &quot;html_strip&quot;, &quot;&amp;_to_and&quot; ],</span><br><span class="line">                    &quot;tokenizer&quot;:    &quot;standard&quot;,</span><br><span class="line">                    &quot;filter&quot;:       [ &quot;lowercase&quot;, &quot;my_stopwords&quot; ]</span><br><span class="line">            &#125;&#125;</span><br><span class="line">        &#125; </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"> GET &#x2F;my_index&#x2F;_mapping</span><br><span class="line"> GET &#x2F;mymyindex&#x2F;_mapping</span><br><span class="line"> </span><br><span class="line">POST &#x2F;lib&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;I have, photos&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST &#x2F;lib&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;letter&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog&#39;s bone&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">POST _analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;lowercase&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog&#39;s bone.&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST _analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;whitespace&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog&#39;s bone.&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST _analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;whitespace&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;The 2 QUICK Brown-Foxes jumped over the lazy dog&#39;s bone.&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST _analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;uax_url_email&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;Email me at john.smith@global-international.com&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">PUT &#x2F;asciifold_example</span><br><span class="line">&#123;</span><br><span class="line">    &quot;settings&quot; : &#123;</span><br><span class="line">        &quot;analysis&quot; : &#123;</span><br><span class="line">            &quot;analyzer&quot; : &#123;</span><br><span class="line">                &quot;default&quot; : &#123;</span><br><span class="line">                    &quot;tokenizer&quot; : &quot;standard&quot;,</span><br><span class="line">                    &quot;filter&quot; : [&quot;standard&quot;, &quot;asciifolding&quot;]</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">DELETE &#x2F;kstem-filter</span><br><span class="line"></span><br><span class="line">PUT &#x2F;kstem-filter</span><br><span class="line">&#123;</span><br><span class="line">  &quot;settings&quot;: &#123;</span><br><span class="line">    &quot;analysis&quot;: &#123;</span><br><span class="line">      &quot;filter&quot;: &#123;</span><br><span class="line">        &quot;myfilter&quot;:&#123;</span><br><span class="line">          &quot;type&quot;: &quot;kstem&quot;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;, </span><br><span class="line">      &quot;analyzer&quot;: &#123;</span><br><span class="line">        &quot;defulat&quot;: &#123;</span><br><span class="line">          &quot;tokenizer&quot;: &quot;standard&quot;,</span><br><span class="line">          &quot;filter&quot;: [&quot;lowercase&quot;, &quot;myfilter&quot;]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">GET kstem-filter&#x2F;_settings</span><br><span class="line">POST &#x2F;kstem-filter&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot;standard&quot;, </span><br><span class="line">  &quot;text&quot;: &quot;Austrian&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">GET &#x2F;n-gram-filter&#x2F;_analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;text&quot;: &quot;ilikebeijingjingbei&quot;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">POST _analyze</span><br><span class="line">&#123;</span><br><span class="line">  &quot;tokenizer&quot;: &quot; synonyms&quot;,</span><br><span class="line">  &quot;text&quot;: &quot;Email me at john.smith@global-international.com&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>lazytime
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://whitestore.top/2020/07/26/note9/" title="ElasticSearch6.2.4 踩坑">https://whitestore.top/2020/07/26/note9/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/ElasticSearch/" rel="tag"># ElasticSearch</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/07/26/note8/" rel="prev" title="小技巧：Typera如何设置高亮和自定义快捷键？">
      <i class="fa fa-chevron-left"></i> 小技巧：Typera如何设置高亮和自定义快捷键？
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/07/26/note10/" rel="next" title="Neo4j 学习笔记">
      Neo4j 学习笔记 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#ElasticSearch-踩坑-6-2-4-版本"><span class="nav-number">1.</span> <span class="nav-text">ElasticSearch 踩坑 - 6.2.4 版本</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#目标"><span class="nav-number">2.</span> <span class="nav-text">目标</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#自定义评分器"><span class="nav-number">2.1.</span> <span class="nav-text">自定义评分器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#智能推荐："><span class="nav-number">2.2.</span> <span class="nav-text">智能推荐：</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#目录"><span class="nav-number">3.</span> <span class="nav-text">目录</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#官方改变1"><span class="nav-number">4.</span> <span class="nav-text">官方改变1</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#RestFul请求需要加入Header"><span class="nav-number">4.1.</span> <span class="nav-text">RestFul请求需要加入Header</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#官方改变2："><span class="nav-number">5.</span> <span class="nav-text">官方改变2：</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#分词器-N元语法ngram"><span class="nav-number">5.1.</span> <span class="nav-text">分词器 N元语法ngram</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#1-基本使用"><span class="nav-number">6.</span> <span class="nav-text">1. 基本使用</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-1-创建索引"><span class="nav-number">6.1.</span> <span class="nav-text">1.1 创建索引</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-查看索引信息"><span class="nav-number">6.2.</span> <span class="nav-text">1.2 查看索引信息:</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-3-创建类型"><span class="nav-number">6.3.</span> <span class="nav-text">1.3 创建类型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-2-指定id的方式："><span class="nav-number">6.3.1.</span> <span class="nav-text">1.3.2 指定id的方式：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-1-不指定id的方式"><span class="nav-number">6.3.2.</span> <span class="nav-text">1.3.1 不指定id的方式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-4-创建一个文档"><span class="nav-number">6.4.</span> <span class="nav-text">1.4 创建一个文档</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-基础搜索"><span class="nav-number">7.</span> <span class="nav-text">2. 基础搜索</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#2-1-使用query-进行搜索"><span class="nav-number">7.1.</span> <span class="nav-text">2.1 使用query 进行搜索</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#原始方式"><span class="nav-number">7.1.1.</span> <span class="nav-text">原始方式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#kibana方式"><span class="nav-number">7.1.2.</span> <span class="nav-text">kibana方式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-1-如果只想查找一个字段，可以使用term"><span class="nav-number">7.1.2.1.</span> <span class="nav-text">2.1.1 如果只想查找一个字段，可以使用term</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-2-过滤器"><span class="nav-number">7.2.</span> <span class="nav-text">2.2 过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-1-ES6以下："><span class="nav-number">7.2.1.</span> <span class="nav-text">2.2.1 ES6以下：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-2-ES6及以上："><span class="nav-number">7.2.2.</span> <span class="nav-text">2.2.2 ES6及以上：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-3-应用聚集"><span class="nav-number">7.3.</span> <span class="nav-text">2.3 应用聚集</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-1-ES6以下："><span class="nav-number">7.3.1.</span> <span class="nav-text">2.3.1 ES6以下：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-2-ES6及以上："><span class="nav-number">7.3.2.</span> <span class="nav-text">2.3.2 ES6及以上：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-4-通过Id获取文档"><span class="nav-number">7.4.</span> <span class="nav-text">2.4 通过Id获取文档</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-elasticsearch配置"><span class="nav-number">8.</span> <span class="nav-text">3. elasticsearch配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#3-1-指定集群名称："><span class="nav-number">8.1.</span> <span class="nav-text">3.1 指定集群名称：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-2-指定详细的日志记录"><span class="nav-number">8.2.</span> <span class="nav-text">3.2 指定详细的日志记录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-3-调整虚拟机大小"><span class="nav-number">8.3.</span> <span class="nav-text">3.3 调整虚拟机大小</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-1-linux-使用如下命令："><span class="nav-number">8.3.1.</span> <span class="nav-text">3.3.1 linux 使用如下命令：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-2-使用elasticsearch-yml修改启动堆内存大小"><span class="nav-number">8.3.2.</span> <span class="nav-text">3.3.2 使用elasticsearch.yml修改启动堆内存大小</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-3-使用修改bin-elasticsearch-in-sh-修改"><span class="nav-number">8.3.3.</span> <span class="nav-text">3.3.3 使用修改bin&#x2F;elasticsearch.in.sh 修改</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-4-集群中加入节点"><span class="nav-number">8.4.</span> <span class="nav-text">3.4 集群中加入节点</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-1-查看节点状态"><span class="nav-number">8.4.1.</span> <span class="nav-text">3.4.1 查看节点状态</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-映射-mapping"><span class="nav-number">9.</span> <span class="nav-text">4. 映射_mapping</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1-检索和自定义映射"><span class="nav-number">9.1.</span> <span class="nav-text">4.1 检索和自定义映射</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-1-获取目前的映射"><span class="nav-number">9.1.1.</span> <span class="nav-text">4.1.1 获取目前的映射</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-2-获取自动生成的映射"><span class="nav-number">9.1.2.</span> <span class="nav-text">4.1.2 获取自动生成的映射</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-3-定义新的映射"><span class="nav-number">9.1.3.</span> <span class="nav-text">4.1.3 定义新的映射</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#es6以下版本"><span class="nav-number">9.1.3.1.</span> <span class="nav-text">es6以下版本</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#es6以上版本"><span class="nav-number">9.1.3.2.</span> <span class="nav-text">es6以上版本</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-4-改变现有字段类型的方法："><span class="nav-number">9.1.4.</span> <span class="nav-text">4.1.4 改变现有字段类型的方法：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-2-用于定义文档字段的核心类型"><span class="nav-number">9.2.</span> <span class="nav-text">4.2 用于定义文档字段的核心类型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-1-定义映射当中的index选项"><span class="nav-number">9.2.1.</span> <span class="nav-text">4.2.1 定义映射当中的index选项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-2-如何创建嵌套类型："><span class="nav-number">9.2.2.</span> <span class="nav-text">4.2.2 如何创建嵌套类型：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-3-定义多字段和数组类型"><span class="nav-number">9.2.3.</span> <span class="nav-text">4.2.3 定义多字段和数组类型</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-3-使用预定义字段"><span class="nav-number">9.3.</span> <span class="nav-text">4.3 使用预定义字段</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-1-控制如何存储和搜索文档"><span class="nav-number">9.3.1.</span> <span class="nav-text">4.3.1 控制如何存储和搜索文档</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-4-更新现有文档"><span class="nav-number">9.4.</span> <span class="nav-text">4.4 更新现有文档</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-4-1-文档更新包含如下步骤："><span class="nav-number">9.4.1.</span> <span class="nav-text">4.4.1 文档更新包含如下步骤：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-5-删除文档"><span class="nav-number">9.5.</span> <span class="nav-text">4.5 删除文档</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-1-删除文档的方式"><span class="nav-number">9.5.1.</span> <span class="nav-text">4.5.1 删除文档的方式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-2-删除文档"><span class="nav-number">9.5.2.</span> <span class="nav-text">4.5.2 删除文档</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-3-删除单个文档"><span class="nav-number">9.5.3.</span> <span class="nav-text">4.5.3 删除单个文档</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-4-删除映射类型和删除查询匹配的文档"><span class="nav-number">9.5.4.</span> <span class="nav-text">4.5.4 删除映射类型和删除查询匹配的文档</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-5-删除索引"><span class="nav-number">9.5.5.</span> <span class="nav-text">4.5.5 删除索引</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-6-关闭和开发索引"><span class="nav-number">9.5.6.</span> <span class="nav-text">4.5.6 关闭和开发索引</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5-版本控制"><span class="nav-number">10.</span> <span class="nav-text">5. 版本控制</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#5-1-乐观锁"><span class="nav-number">10.1.</span> <span class="nav-text">5.1 乐观锁</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-1-内部版本控制"><span class="nav-number">10.1.1.</span> <span class="nav-text">5.1.1 内部版本控制</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-2-外部版本控制"><span class="nav-number">10.1.2.</span> <span class="nav-text">5.1.2 外部版本控制</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-2-自动重试"><span class="nav-number">10.2.</span> <span class="nav-text">5.2 自动重试</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-搜索与高级搜索分析"><span class="nav-number">11.</span> <span class="nav-text">6. 搜索与高级搜索分析</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#6-1-搜索请求的基本模块"><span class="nav-number">11.1.</span> <span class="nav-text">6.1 搜索请求的基本模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-2-基于url的搜索请求"><span class="nav-number">11.2.</span> <span class="nav-text">6.2 基于url的搜索请求</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2-1-基于from-和szize的参数来实现结果分页"><span class="nav-number">11.2.1.</span> <span class="nav-text">6.2.1 基于from 和szize的参数来实现结果分页</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2-2-改变结果的顺序"><span class="nav-number">11.2.2.</span> <span class="nav-text">6.2.2 改变结果的顺序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2-3-搜索结果当中限制-source-字段"><span class="nav-number">11.2.3.</span> <span class="nav-text">6.2.3 搜索结果当中限制_source 字段</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2-4-匹配查询"><span class="nav-number">11.2.4.</span> <span class="nav-text">6.2.4 匹配查询</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-3-基于请求主体的搜索请求"><span class="nav-number">11.3.</span> <span class="nav-text">6.3 基于请求主体的搜索请求</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-3-1-使用from-和-size，参数结果分页"><span class="nav-number">11.3.1.</span> <span class="nav-text">6.3.1 使用from 和 size，参数结果分页</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-3-2-过滤返回-source-内容"><span class="nav-number">11.3.2.</span> <span class="nav-text">6.3.2 过滤返回_source 内容</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#在source字段当中返回通配符"><span class="nav-number">11.3.2.1.</span> <span class="nav-text">在source字段当中返回通配符</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#通过include以及exclude-过滤返回-source的内容"><span class="nav-number">11.3.2.2.</span> <span class="nav-text">通过include以及exclude 过滤返回_source的内容</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-3-3-基于结果的排序"><span class="nav-number">11.3.3.</span> <span class="nav-text">6.3.3 基于结果的排序</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-4-实践中的基础模块"><span class="nav-number">11.4.</span> <span class="nav-text">6.4 实践中的基础模块</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-4-1-理解回复的内容"><span class="nav-number">11.4.1.</span> <span class="nav-text">6.4.1 理解回复的内容</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-5-查询和过滤器DSL-（重点）"><span class="nav-number">11.5.</span> <span class="nav-text">6.5 查询和过滤器DSL （重点）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-5-1-match-查询和term过滤器"><span class="nav-number">11.5.1.</span> <span class="nav-text">6.5.1 match 查询和term过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#过滤器和查询器有什么不同："><span class="nav-number">11.5.1.1.</span> <span class="nav-text">过滤器和查询器有什么不同：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#es6以下-以及旧版本使用的方式"><span class="nav-number">11.5.1.2.</span> <span class="nav-text">es6以下 以及旧版本使用的方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#这里需要注意下面使用的是es6以及以上版本"><span class="nav-number">11.5.1.3.</span> <span class="nav-text">这里需要注意下面使用的是es6以及以上版本</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-6-常用的基础查询和过滤器"><span class="nav-number">11.6.</span> <span class="nav-text">6.6 常用的基础查询和过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-6-1-match-all-的使用场景"><span class="nav-number">11.6.1.</span> <span class="nav-text">6.6.1 match_all 的使用场景</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-6-2-query-string-查询"><span class="nav-number">11.6.2.</span> <span class="nav-text">6.6.2 query_string 查询</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#使用query-string-进行复杂的查询"><span class="nav-number">11.6.2.1.</span> <span class="nav-text">使用query_string 进行复杂的查询</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-6-3-term-查询和-term过滤器"><span class="nav-number">11.6.3.</span> <span class="nav-text">6.6.3 term 查询和 term过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#使用term-过滤器的得分，和term查询器的得分对比"><span class="nav-number">11.6.3.1.</span> <span class="nav-text">使用term 过滤器的得分，和term查询器的得分对比</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-6-4-terms-查询"><span class="nav-number">11.6.4.</span> <span class="nav-text">6.6.4 terms 查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-5-5-match查询和-term过滤器"><span class="nav-number">11.6.5.</span> <span class="nav-text">6.5.5 match查询和 term过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#布尔查询行为"><span class="nav-number">11.6.5.1.</span> <span class="nav-text">布尔查询行为</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#词组（phrase-）查询的方式"><span class="nav-number">11.6.5.2.</span> <span class="nav-text">词组（phrase ）查询的方式</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#es5版本以及以下的语法："><span class="nav-number">11.6.5.2.1.</span> <span class="nav-text">es5版本以及以下的语法：</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#es6以及以上要使用以下语法"><span class="nav-number">11.6.5.2.2.</span> <span class="nav-text">es6以及以上要使用以下语法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-5-6-phrase-prefix-查询"><span class="nav-number">11.6.6.</span> <span class="nav-text">6.5.6 phrase_prefix 查询</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#es5-x-版本以及以下的语法："><span class="nav-number">11.6.6.1.</span> <span class="nav-text">es5.x 版本以及以下的语法：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#es6-x-需要改成如下写法"><span class="nav-number">11.6.6.2.</span> <span class="nav-text">es6.x 需要改成如下写法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用multi-match-匹配多个字段"><span class="nav-number">11.6.6.3.</span> <span class="nav-text">使用multi_match 匹配多个字段</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-7-组合查询和复合查询"><span class="nav-number">11.7.</span> <span class="nav-text">6.7 组合查询和复合查询</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-7-1-bool查询"><span class="nav-number">11.7.1.</span> <span class="nav-text">6.7.1 bool查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-7-2-bool-的过滤器"><span class="nav-number">11.7.2.</span> <span class="nav-text">6.7.2 bool 的过滤器</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-8-超越match-和-过滤器的查询"><span class="nav-number">11.8.</span> <span class="nav-text">6.8 超越match 和 过滤器的查询</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-8-1-range-查询和过滤器"><span class="nav-number">11.8.1.</span> <span class="nav-text">6.8.1 range 查询和过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#模拟数据"><span class="nav-number">11.8.1.1.</span> <span class="nav-text">模拟数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#现在需要查找出-11-年到-16年的数据"><span class="nav-number">11.8.1.2.</span> <span class="nav-text">现在需要查找出 11 年到 16年的数据</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-8-2-prefix-查询和过滤器"><span class="nav-number">11.8.2.</span> <span class="nav-text">6.8.2 prefix 查询和过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#在过滤器当中使用"><span class="nav-number">11.8.2.1.</span> <span class="nav-text">在过滤器当中使用</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-8-3-wildcard-查询"><span class="nav-number">11.8.3.</span> <span class="nav-text">6.8.3 wildcard 查询</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-9-使用过滤器查询字段的存在性"><span class="nav-number">11.9.</span> <span class="nav-text">6.9 使用过滤器查询字段的存在性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-9-1-exists-过滤器"><span class="nav-number">11.9.1.</span> <span class="nav-text">6.9.1 exists 过滤器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-9-2-missing-过滤器（6-x以上版本已经删除）"><span class="nav-number">11.9.2.</span> <span class="nav-text">6.9.2 missing 过滤器（6.x以上版本已经删除）</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#作为测试-先插入一条增加一个字段的数据"><span class="nav-number">11.9.2.1.</span> <span class="nav-text">作为测试,先插入一条增加一个字段的数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#接下来，查找字段里没有的值-这样写是错误的，没有正确写法（6-x）"><span class="nav-number">11.9.2.2.</span> <span class="nav-text">接下来，查找字段里没有的值,这样写是错误的，没有正确写法（6.x）</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-9-3-将任何查询转为过滤器"><span class="nav-number">11.9.3.</span> <span class="nav-text">6.9.3 将任何查询转为过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#缓存过滤器"><span class="nav-number">11.9.3.1.</span> <span class="nav-text">缓存过滤器</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-9-4-为任务选择最好的查询"><span class="nav-number">11.9.4.</span> <span class="nav-text">6.9.4 为任务选择最好的查询</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#7-分析数据"><span class="nav-number">12.</span> <span class="nav-text">7. 分析数据</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#7-1-什么是分析数据"><span class="nav-number">12.1.</span> <span class="nav-text">7.1 什么是分析数据</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-1-1-字符过滤"><span class="nav-number">12.1.1.</span> <span class="nav-text">7.1.1 字符过滤</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-1-2-切分为分词"><span class="nav-number">12.1.2.</span> <span class="nav-text">7.1.2 切分为分词</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-1-3-分词过滤器"><span class="nav-number">12.1.3.</span> <span class="nav-text">7.1.3 分词过滤器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-1-4-分词索引"><span class="nav-number">12.1.4.</span> <span class="nav-text">7.1.4 分词索引</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-2-为文档使用分析器"><span class="nav-number">12.2.</span> <span class="nav-text">7.2 为文档使用分析器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-2-1-创建索引的过程中，添加定制分析器"><span class="nav-number">12.2.1.</span> <span class="nav-text">7.2.1 创建索引的过程中，添加定制分析器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#旧版本的使用方式"><span class="nav-number">12.2.1.1.</span> <span class="nav-text">旧版本的使用方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#网上的案例："><span class="nav-number">12.2.1.2.</span> <span class="nav-text">网上的案例：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#将书上的案例改为6-x支持的形式，格式如下"><span class="nav-number">12.2.1.3.</span> <span class="nav-text">将书上的案例改为6.x支持的形式，格式如下:</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-2-2-使用elasticsearch-yml-的配置文件进行配置"><span class="nav-number">12.2.2.</span> <span class="nav-text">7.2.2 使用elasticsearch.yml 的配置文件进行配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-2-3-在映射中指定某个字段的分析器"><span class="nav-number">12.2.3.</span> <span class="nav-text">7.2.3 在映射中指定某个字段的分析器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#书本的方式已经不适用于6-x版本了，根据官方文档的内容要进行如下定义"><span class="nav-number">12.2.3.1.</span> <span class="nav-text">书本的方式已经不适用于6.x版本了，根据官方文档的内容要进行如下定义</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-3-使用API来分析文本"><span class="nav-number">12.3.</span> <span class="nav-text">7.3 使用API来分析文本</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-3-1-使用-analyzer-内置API来进行分析分析器解析步骤"><span class="nav-number">12.3.1.</span> <span class="nav-text">7.3.1 使用_analyzer 内置API来进行分析分析器解析步骤</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-3-2-分析中指定自定义分析器"><span class="nav-number">12.3.2.</span> <span class="nav-text">7.3.2 分析中指定自定义分析器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-3-3-使用组合即时创建分析器"><span class="nav-number">12.3.3.</span> <span class="nav-text">7.3.3 使用组合即时创建分析器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#使用curl方式"><span class="nav-number">12.3.3.1.</span> <span class="nav-text">使用curl方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用kibana方式"><span class="nav-number">12.3.3.2.</span> <span class="nav-text">使用kibana方式</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-3-4-使用基于某个字段的映射分析"><span class="nav-number">12.3.4.</span> <span class="nav-text">7.3.4 使用基于某个字段的映射分析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-3-5-使用词条向量API来学习索引词条"><span class="nav-number">12.3.5.</span> <span class="nav-text">7.3.5 使用词条向量API来学习索引词条</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-4-分析器-分词器和分词过滤器"><span class="nav-number">12.4.</span> <span class="nav-text">7.4 分析器&#x2F;分词器和分词过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-4-0-分析器的概览"><span class="nav-number">12.4.1.</span> <span class="nav-text">7.4.0 分析器的概览</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-4-1-内置分析器"><span class="nav-number">12.4.2.</span> <span class="nav-text">7.4.1 内置分析器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#标准分析器"><span class="nav-number">12.4.2.1.</span> <span class="nav-text">标准分析器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#简单分析器"><span class="nav-number">12.4.2.2.</span> <span class="nav-text">简单分析器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#空白分析器"><span class="nav-number">12.4.2.3.</span> <span class="nav-text">空白分析器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#停止分析器"><span class="nav-number">12.4.2.4.</span> <span class="nav-text">停止分析器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#关键字分析器"><span class="nav-number">12.4.2.5.</span> <span class="nav-text">关键字分析器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#模式分析器"><span class="nav-number">12.4.2.6.</span> <span class="nav-text">模式分析器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#语言分析器"><span class="nav-number">12.4.2.7.</span> <span class="nav-text">语言分析器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#指纹分析器"><span class="nav-number">12.4.2.8.</span> <span class="nav-text">指纹分析器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#雪球分析器"><span class="nav-number">12.4.2.9.</span> <span class="nav-text">雪球分析器</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-4-2-分词器"><span class="nav-number">12.4.3.</span> <span class="nav-text">7.4.2 分词器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#标准分词器"><span class="nav-number">12.4.3.1.</span> <span class="nav-text">标准分词器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#字母分词器"><span class="nav-number">12.4.3.2.</span> <span class="nav-text">字母分词器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#小写分词器"><span class="nav-number">12.4.3.3.</span> <span class="nav-text">小写分词器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#空格分词器"><span class="nav-number">12.4.3.4.</span> <span class="nav-text">空格分词器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#UAX-URL电子邮件令牌生成器"><span class="nav-number">12.4.3.5.</span> <span class="nav-text">UAX URL电子邮件令牌生成器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#经典分词器"><span class="nav-number">12.4.3.6.</span> <span class="nav-text">经典分词器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#泰语分词器"><span class="nav-number">12.4.3.7.</span> <span class="nav-text">泰语分词器</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-4-3-分词过滤器"><span class="nav-number">12.4.4.</span> <span class="nav-text">7.4.3 分词过滤器</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#标准分词过滤器"><span class="nav-number">12.4.4.1.</span> <span class="nav-text">标准分词过滤器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ASCII-Folding-Token-Filter（ASCII折叠过滤器）"><span class="nav-number">12.4.4.2.</span> <span class="nav-text">ASCII Folding Token Filter（ASCII折叠过滤器）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Flatten-Graph-Token-Filter（图形分词过滤器）"><span class="nav-number">12.4.4.3.</span> <span class="nav-text">Flatten Graph Token Filter（图形分词过滤器）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Length-Token-Filter（长度分词过滤器）"><span class="nav-number">12.4.4.4.</span> <span class="nav-text">Length Token Filter（长度分词过滤器）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Lowercase-token-filter（小写分词过滤器）"><span class="nav-number">12.4.4.5.</span> <span class="nav-text">Lowercase token filter（小写分词过滤器）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Uppercase-Token-Filter（大写分词过滤器）"><span class="nav-number">12.4.4.6.</span> <span class="nav-text">Uppercase Token Filter（大写分词过滤器）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#NGram-Token-Filter（N元语法过滤器）"><span class="nav-number">12.4.4.7.</span> <span class="nav-text">NGram Token Filter（N元语法过滤器）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Edge-NGram-Token-Filter（侧边N元语法过滤器）"><span class="nav-number">12.4.4.8.</span> <span class="nav-text">Edge NGram Token Filter（侧边N元语法过滤器）</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-4-4-N元语法的使用场景以及使用案例"><span class="nav-number">12.4.5.</span> <span class="nav-text">7.4.4 N元语法的使用场景以及使用案例</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#使用案例"><span class="nav-number">12.4.5.1.</span> <span class="nav-text">使用案例:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Shingle-Token-Filter（滑动窗口分词过滤器）"><span class="nav-number">12.4.5.2.</span> <span class="nav-text">Shingle Token Filter（滑动窗口分词过滤器）</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-5-提取词干"><span class="nav-number">12.5.</span> <span class="nav-text">7.5 提取词干</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-5-1-算分提取词干"><span class="nav-number">12.5.1.</span> <span class="nav-text">7.5.1 算分提取词干</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#选取kstem-作为案例测试"><span class="nav-number">12.5.1.1.</span> <span class="nav-text">选取kstem 作为案例测试</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-5-2-使用字典提取词干"><span class="nav-number">12.5.2.</span> <span class="nav-text">7.5.2 使用字典提取词干</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#8-使用相关性进行搜索"><span class="nav-number">13.</span> <span class="nav-text">8. 使用相关性进行搜索</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#8-1-es-的打分机制"><span class="nav-number">13.1.</span> <span class="nav-text">8.1 es 的打分机制</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-1-1-文档是如何运作的："><span class="nav-number">13.1.1.</span> <span class="nav-text">8.1.1 文档是如何运作的：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-1-2-词频"><span class="nav-number">13.1.2.</span> <span class="nav-text">8.1.2 词频</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-1-3-逆文档词频"><span class="nav-number">13.1.3.</span> <span class="nav-text">8.1.3 逆文档词频</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-1-4-Lucene-评分公式"><span class="nav-number">13.1.4.</span> <span class="nav-text">8.1.4 Lucene 评分公式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-2-其他打分方式"><span class="nav-number">13.2.</span> <span class="nav-text">8.2 其他打分方式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#如何指定索引的打分方式？"><span class="nav-number">13.2.1.</span> <span class="nav-text">如何指定索引的打分方式？</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-3-索引期间Boosting"><span class="nav-number">13.3.</span> <span class="nav-text">8.3 索引期间Boosting</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-4-查询期间的Boosting"><span class="nav-number">13.4.</span> <span class="nav-text">8.4 查询期间的Boosting</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-4-1-跨越多个字段的查询"><span class="nav-number">13.4.1.</span> <span class="nav-text">8.4.1 跨越多个字段的查询</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-4-2-使用multi-match-查询，指定整个Boost"><span class="nav-number">13.4.2.</span> <span class="nav-text">8.4.2 使用multi_match 查询，指定整个Boost</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-4-3-使用特殊符号-对于name-进行boost"><span class="nav-number">13.4.3.</span> <span class="nav-text">8.4.3 使用特殊符号^对于name 进行boost</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-4-4-query-string-中对于针对单个的词条进行boost"><span class="nav-number">13.4.4.</span> <span class="nav-text">8.4.4 query_string 中对于针对单个的词条进行boost</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-5-使用”解释-explain-”来理解文档评分"><span class="nav-number">13.5.</span> <span class="nav-text">8.5 使用”解释(explain)”来理解文档评分</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-5-1-解释一篇文档不匹配的原因"><span class="nav-number">13.5.1.</span> <span class="nav-text">8.5.1 解释一篇文档不匹配的原因</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-6-使用查询再打分来减小评分操作影响"><span class="nav-number">13.6.</span> <span class="nav-text">8.6 使用查询再打分来减小评分操作影响</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-6-1-官方文档介绍-6-2版本"><span class="nav-number">13.6.1.</span> <span class="nav-text">8.6.1 官方文档介绍 6.2版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-6-2-使用rescore-特性，对于匹配文档子集再评分"><span class="nav-number">13.6.2.</span> <span class="nav-text">8.6.2 使用rescore 特性，对于匹配文档子集再评分</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-7-function-score-来定制得分"><span class="nav-number">13.7.</span> <span class="nav-text">8.7 function_score 来定制得分</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-7-1-function-score-的基本结构"><span class="nav-number">13.7.1.</span> <span class="nav-text">8.7.1 function_score 的基本结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-7-2-weight-函数"><span class="nav-number">13.7.2.</span> <span class="nav-text">8.7.2 weight 函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#可以指定多个weight函数"><span class="nav-number">13.7.2.1.</span> <span class="nav-text">可以指定多个weight函数</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-7-3-合并得分"><span class="nav-number">13.7.3.</span> <span class="nav-text">8.7.3 合并得分</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-7-4-field-value-factor-函数"><span class="nav-number">13.7.4.</span> <span class="nav-text">8.7.4 field_value_factor 函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-7-5-在function-score-查询中使用field-value-factor"><span class="nav-number">13.7.5.</span> <span class="nav-text">8.7.5 在function_score 查询中使用field_value_factor</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-8-painless脚本-5-0后go语言脚本支持已删除"><span class="nav-number">13.8.</span> <span class="nav-text">8.8 painless脚本(5.0后go语言脚本支持已删除)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-7-5-random-score-函数"><span class="nav-number">13.8.1.</span> <span class="nav-text">8.7.5 random_score 函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-7-6-衰减函数"><span class="nav-number">13.8.2.</span> <span class="nav-text">8.7.6 衰减函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#官方文档"><span class="nav-number">13.8.2.1.</span> <span class="nav-text">官方文档</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#配置选项"><span class="nav-number">13.8.2.2.</span> <span class="nav-text">配置选项</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-9-使用脚本排序"><span class="nav-number">13.9.</span> <span class="nav-text">8.9 使用脚本排序</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#9-Elasticsearch-REST-API-的学习使用"><span class="nav-number">14.</span> <span class="nav-text">9. Elasticsearch REST API 的学习使用</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#9-0-API官网"><span class="nav-number">14.1.</span> <span class="nav-text">9.0 API官网</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-1-REST-低级-Api"><span class="nav-number">14.2.</span> <span class="nav-text">9.1 REST 低级 Api</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#9-1-1-起步"><span class="nav-number">14.2.1.</span> <span class="nav-text">9.1.1 起步</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-1-2-初始化"><span class="nav-number">14.2.2.</span> <span class="nav-text">9.1.2 初始化</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-1-3-执行请求"><span class="nav-number">14.2.3.</span> <span class="nav-text">9.1.3 执行请求</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-1-4-接受响应体的处理"><span class="nav-number">14.2.4.</span> <span class="nav-text">9.1.4 接受响应体的处理</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-2-REST-高级-API"><span class="nav-number">14.3.</span> <span class="nav-text">9.2 REST 高级 API</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#9-2-1-机器翻译介绍"><span class="nav-number">14.3.1.</span> <span class="nav-text">9.2.1 机器翻译介绍</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-2-2-兼容性"><span class="nav-number">14.3.2.</span> <span class="nav-text">9.2.2 兼容性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-2-3-起步"><span class="nav-number">14.3.3.</span> <span class="nav-text">9.2.3 起步</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-2-4-创建一个rest-连接"><span class="nav-number">14.3.4.</span> <span class="nav-text">9.2.4 创建一个rest 连接</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-2-5-【6-2-4】版本-支持的相关API-（重点）"><span class="nav-number">14.3.5.</span> <span class="nav-text">9.2.5 【6.2.4】版本 支持的相关API （重点）</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#创建索引"><span class="nav-number">14.3.5.1.</span> <span class="nav-text">创建索引</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#删除索引"><span class="nav-number">14.3.5.2.</span> <span class="nav-text">删除索引</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#开放索引"><span class="nav-number">14.3.5.3.</span> <span class="nav-text">开放索引</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#关闭索引"><span class="nav-number">14.3.5.4.</span> <span class="nav-text">关闭索引</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-2-6-索引本身的API"><span class="nav-number">14.3.6.</span> <span class="nav-text">9.2.6 索引本身的API</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#直接根据索引创建一个文档需要如下参数"><span class="nav-number">14.3.6.1.</span> <span class="nav-text">直接根据索引创建一个文档需要如下参数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#提供文档来源的多种方式"><span class="nav-number">14.3.6.2.</span> <span class="nav-text">提供文档来源的多种方式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#可选参数"><span class="nav-number">14.3.6.3.</span> <span class="nav-text">可选参数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#获取响应内容"><span class="nav-number">14.3.6.4.</span> <span class="nav-text">获取响应内容</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#根据上述内容整合"><span class="nav-number">14.3.6.5.</span> <span class="nav-text">根据上述内容整合</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#10-Elasticsearch-JAVA-API-的学习使用"><span class="nav-number">15.</span> <span class="nav-text">10. Elasticsearch JAVA API 的学习使用</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#10-1-起步："><span class="nav-number">15.1.</span> <span class="nav-text">10.1 起步：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#10-1-1-Maven-依赖"><span class="nav-number">15.1.1.</span> <span class="nav-text">10.1.1 Maven 依赖</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#11-Es-painless-脚本插件使用（Elasticsearch-script-plugin）"><span class="nav-number">16.</span> <span class="nav-text">11. Es painless 脚本插件使用（Elasticsearch script plugin）</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#11-1-前置条件：windows安装gradle"><span class="nav-number">16.1.</span> <span class="nav-text">11.1 前置条件：windows安装gradle</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#11-1-1-官方下载地址"><span class="nav-number">16.1.1.</span> <span class="nav-text">11.1.1 官方下载地址</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-1-2-将gradle放入合适位置，将gradle加入path环境变量"><span class="nav-number">16.1.2.</span> <span class="nav-text">11.1.2 将gradle放入合适位置，将gradle加入path环境变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-1-3-配置阿里云的镜像"><span class="nav-number">16.1.3.</span> <span class="nav-text">11.1.3 配置阿里云的镜像</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#N-kibana-学习es的所有内容"><span class="nav-number">17.</span> <span class="nav-text">N kibana 学习es的所有内容</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#2019-10-14"><span class="nav-number">17.1.</span> <span class="nav-text">2019.10.14</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2019-10-15"><span class="nav-number">17.2.</span> <span class="nav-text">2019.10.15</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿东</p>
  <div class="site-description" itemprop="description">随遇而安</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">239</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lazyTimes"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjEwOTc0ODM1MDhAcXEuY29t" title="E-Mail → mailto:1097483508@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly93d3cuNTJwb2ppZS5jbi9ob21lLnBocD9tb2Q9c3BhY2UmdWlkPTE0OTc3MTgmZG89dGhyZWFkJnZpZXc9bWUmZnJvbT1zcGFjZQ==" title="https:&#x2F;&#x2F;www.52pojie.cn&#x2F;home.php?mod&#x3D;space&amp;uid&#x3D;1497718&amp;do&#x3D;thread&amp;view&#x3D;me&amp;from&#x3D;space">吾爱破解</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vdXNlci8yOTk5MTIzNDUyNjI2MzY2" title="https:&#x2F;&#x2F;juejin.im&#x2F;user&#x2F;2999123452626366">掘金</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3UvbGF6eXRpbWVz" title="https:&#x2F;&#x2F;segmentfault.com&#x2F;u&#x2F;lazytimes">思否</span>
        </li>
    </ul>
  </div>

      </div>

      <div class="wechat_OA">
        <span>欢迎关注我的公众号</span>
        <br>
          <!-- 这里添加你的二维码图片 -->
        <img src ="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/wechat_channel.jpg">
      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿东</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">2m</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">29:50</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'qMUpEEvBgXaMDD1b0ftgi9xr-gzGzoHsz',
      appKey     : 'UCdfT4Rfih6MO6y8DI4fstf6',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
